Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting a textbox to a data field at run time using code

Status
Not open for further replies.

NickBlake

Programmer
Nov 28, 2003
10
0
0
GB
Can anyone tell me how I can connect a textbox to a datafield using code whilst my program is running in VB6.
 
Setting the TextBox Datasource and DataMember properties will bind the Textbox

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 

> Datasource and DataMember

DataSource and DataField, and possibly DataMember.

DataMember is used when you are using a DataProvider Class (or the DE), for instance in order to determine which recordset with-in the data class to use.

Text1.DataField = "SomeFieldName"
Text1.DataSource = MyRecordset
 

Oops:

Text1.DataField = "SomeFieldName"
Set Text1.DataSource = MyRecordset
 
Thanks CCLINT - clumsy typo on my part!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Thanks for the reply that works but not for what I want to do.

What I am doing is creating a fault logging database whereby a new unique reference number is created every time a fault is logged.

I am doing this by connecting a data control to a table to obtain a number and then adding 1 to the number and saving it back to the table once the call has been saved.

What i am also doing is saving all the call information such as name, date, fault etc to another table and the fields are connected to another data control.

This works fine for all the empty fields connected to my data control because upon loading a form a new record is created so the fields are blank. However the ref number field is also blank but I want it to hold the reference number that I have obtained from the other table. Do you know of any way that I can do this.
 


>Thanks for the reply that works but not for what I want to do.

[mad] Well, that's exactly what you asked for...


Stick the value you want to retain into a variable
 
Sorry for the confusion CCLINT.

This is the code I am using maybe this will help

Private Sub form_load()

Data2.Refresh
Data2.Recordset.AddNew
Data3.Refresh
temp = (CInt(txtBssRef))
ref = (temp + 1)
lblBssRef.Caption = ref
txtBssRef.Text = ref
txtWriteBssRef.text = ref
Data3.Refresh

where txtBssRef is connected to a table via data3 and txtWriteBssRef is connected to a table via data2 and also connected to a datafield in this table.

However after running through the above code txtWriteBssRef.text is still blank and does not equal ref. I think that this is because on form load because the field the textbox is connected to is blank then this is blank but I don't know why the line of code doesn't overwrite it.
 
Data2.Refresh
Data2.Recordset.AddNew
Data3.Refresh


temp = (CInt(txtBssRef))
'Or:
'temp = (CInt(Data3.Recordset.Fields(txtBssRef.DataField).Value))

'Not sure about this line. If I understand correctly, then it would be better to do a cancel:
Data3.Refresh
Data3.Recordset.CancelUpdate

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top