textbox from one table to another

giana
01-12-2004, 12:27 PM
Hi, I have this vb6 form. It's connected to an acces db via ADO. And it is actually connected to 2 tables. But there's a textbox that I cannot set up properly. The tectbox should read its values from one table ('Employees') and then, when I want to add a record, write it on another table ('Details').
The textbox text is actually an ID number from the Department column.
I set its the DataSource to a recordset and the DataField to "DepartmentID", but I don't know how to make it write to the proper table. Any help?

thanks
giana

couch612
01-12-2004, 08:40 PM
don't use a data control to access your data. populate and save your textboxes using either ADO or DAO data access methods.

for example, here is a DAO code sample to open a database, open a table, then set a textbox to the value of a field in the table. Note that DAO has now been superseeded by ADO, so you might want to use that instead:


sub PopulateTextbox

dim db as database
dim rs as recordset

set db = workspaces(0).opendatabase("c:\mydb.mdb")
set rs = db.openrecordset("Table1")

textbox1.text = rs![Field1]

rs.close
db.close

End sub

vbFace
01-12-2004, 11:40 PM
And for ADO, look into the ADODB.Command object to send "non-returning" SQL to the server, such as Insert, Update, and Delete

SURESH MENON
01-13-2004, 12:00 AM
search for ADO, you will get lot's of example in this forum.

tom2knox
01-13-2004, 02:24 AM
hope this helps you...

search for ADO, you will get lot's of example in this forum.

giana
01-13-2004, 08:15 AM
don't use a data control to access your data. populate and save your textboxes using either ADO or DAO data access methods.
[/VB]

Ok, well first of all thanks to everybody for your replies. But maybe I didn't explain myself well enough.
First of all, I'm not using a DataControl, I'm doing everything via code. The txtboxes and datacombo populates fine. The problem that I have is that I need to write a text of 2 textboxes to a different table from which they originally came.
Also there are to textboxes that do not move with the other recordsets. Anybody?

here's the code that populates the form:
Private Sub Form_Load()
'---All the other recordsets are in the general declaration section---
Call CenterForm(Me)
Dim EventRecSet As Recordset
ConnectBackend 'connects to the database. the connection is in a separate module

Set TimeBilledRS = New Recordset
TimeBilledRS.Open "SELECT EventID, Hours, TotalBilling FROM TimeBilled", conData, adOpenStatic, adLockOptimistic

Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "SELECT DepartmentID, EmployeeID, Date, WeekDayID, HourlyRate, RegularHours, OvertimeHours, TotalRegular, TotalOvertime FROM Details", conData, adOpenStatic, adLockOptimistic

Dim oText As TextBox 'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next

Me.txtHours.Text = TimeBilledRS![Hours]
Me.txtTotalBilling.Text = TimeBilledRS![TotalBilling]

Set EmplRecSet = New Recordset
EmplRecSet.Open "SELECT EmployeeID, Name, DepartmentID, HourlyRate FROM Employees", conData, adOpenStatic, adLockOptimistic

'the following 2 boxes populate, but do not move when I browse the records and give me an error when I try to add another record. Before I added these everything was orking fine, but I need them for report purposes

Me.txtHourlyRate.Text = EmplRecSet![HourlyRate]
Me.txtDepartment.Text = EmplRecSet![DepartmentID]

With Me.dbcmbEmployee 'datacombo
Set .DataSource = adoPrimaryRS
.BoundColumn = "EmployeeID"
.DataField = "EmployeeID"

Set .RowSource = EmplRecSet
.ListField = "Name"
End With

Set EventRecSet = New Recordset
EventRecSet.Open "SELECT EventID, EventName FROM Events", conData, adOpenStatic, adLockOptimistic

With Me.dbcmbEvent 'another datacombo
Set .DataSource = TimeBilledRS
.BoundColumn = "EventID"
.DataField = "EventID"

Set .RowSource = EventRecSet
.ListField = "EventName"
End With

mbDataChanged = False
End Sub

giana
01-13-2004, 09:35 AM
well, ok, now I can add records. I simply had to equal the fields of the 2 recordset in the update event.
But there is still one problem: the 2 textboxes do not move with the other data. Also, when I tried to add their values I get something like 8+2=82....
Anybody??

MKoslof
01-13-2004, 10:35 AM
you text box values probably are not updating as the recordset values are. You might have to repaint the text boxes to force an refresh of the screen and use a DoEvents to make sure all processess are finished before updating the text box....

giana
01-13-2004, 11:36 AM
You might have to repaint the text boxes to force an refresh of the screen and use a DoEvents to make sure all processess are finished before updating the text box....

I'm sorry, but I'm not following you.... :confused:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum