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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to record data from a text box (Subform) to a field (table) 1

Status
Not open for further replies.

fuldingo

Programmer
Jul 1, 2002
12
PK
Thank to blarson0 and taha60 for you response. But i´m still having the same problem but i think that is my fault. I forgot to tell you that i´m working with subforms, i mean, i´ve got a subform with a combo box which Row Source is a query from , let´s say , Table A. With the data of this query, i´m filling the combo box itself and three different text boxes. Now, each time that i play the query using the combo box, i insert a new record in Table B that contains too the Child Field. With a combo box is easy to update the value that contains to Table B using Record Source, but my problem is how to update the value from a text box of this subform to Table B. Also, reviewing the wbe site giving by Taha60 (SQL tutorial), i know too, that what i need is perform a UPDATE instead an INSERT, but i´ve tried unsuccesfully.

If anyone know how to do this, please help me.

Thank you.
 
As you have bound the combo box to TableB correctly - why cann't you bind the text box controls to the text fields in TableB in the same way

Binding a text box control to a field does not stop you setting the vaule of the control at any point using code, like
txtControl = cboComboName.Column(3)
in the combo's After_Update event.

but you can't use something like a DLookup any more.



'ope-that-'elps.

G LS
 
HOWEVER,

Thinking about it a bit more - you should never need to store the text in the table anyway if the text is always the contents of a combo box's column.

If you have stored the combo box's bound column data in a field, and given that this uniquely identifies the record that the combo box links to via it's row source then the contents of the other text boxes are just lookups - and DLoopup() should be user. Normalisation and Data Integrity rules means that you should NEVER store this data in TableB anyway.


G LS
 
Thank you LittleSmudge. I think that your first response is the clue because although i have the data in the combo box, i need to record it in Table B due this data may change in time and i need to have the value used in any time. So, i think that using the coding you used in your first response is going to be enough, but i´m not completely sure how to implement it. Could you give me a little more detail about the coding you gave me ?

Thank you again.

MM

 
Okay,

( I had an idea that the reason would be as you've said - but I wanted to check you were thinking it through correctly )

As for the code

What I mean is on the subform:-
combo box is bound to the field TableB!comboField

Well then bind the three text boxes ( called txtBoxOne, txtBoxTwo, txtBoxThree ) to
TableB!txtFieldOne, TableB!txtFieldTwo, TableB!txtFieldThree
respectively

THEN you select a record from TableA via the RowSource in your comboBox (I'll assume that the first column of the combo box is the Bound column an is bound to TableB!comboField)
Likewise the data in the second, third and fourth columns are to be placed in the text boxes and hence into the fields that I've called txtFieldOne, txtFieldTwo & txtFieldThree respecively

In the AfterUpdate event of your combo box, you put the following code

Private Sub comboBox_AfterUpdate()
txtBoxOne = comboBox.Column(1)
txtBoxTwo = comboBox.Column(2)
txtBoxThree = comboBox.Column(3)
End Sub

This code then places the combo box data into the text boxes and when you update the record they will be automatically stored into the table.

Note: comboBox.Column(x) is a Zero based index so Column(1) is actually the second column along ! {Welcome to the wonderful world of Microsoft}



QED.

G LS
 
Thank you very much, LittleSmudge. Finally i got what i want. I hope we keep in touch.

Fuldingo.

MM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top