combo box problem

G

Guest

I have a combo box and a text box in a subform. When I select a test_name
from the combo box I want the test_id to be placed in a text box on the same
form. The test id gets stored in the main table. I can select a test_name
that uses a query based on a table of test names. However, the test_id field
is not updating when selection is made. Can anyone tell me what I'm doing
wrong?

Code for combo box:
Private Sub Test_Name_BeforeUpdate(Cancel As Integer)
' Update Test_Id To controls based on value selected in Test_Name combo box.
Me!Test_Id = Me!Test_Name.Column(1)

End Sub

Code for the text box:
Private Sub Test_Id_BeforeUpdate(Cancel As Integer)
' Update Test_Name To controls based on value selected in Test_Id combo box.
Me!Test_Name = Me!Test_Id.Column(1)
End Sub

thanks.
 
J

John Vinson

I have a combo box and a text box in a subform. When I select a test_name
from the combo box I want the test_id to be placed in a text box on the same
form. The test id gets stored in the main table. I can select a test_name
that uses a query based on a table of test names. However, the test_id field
is not updating when selection is made. Can anyone tell me what I'm doing
wrong?

I'm not sure why you're going around Robin's barn to do this in the
first place! Typically one would use a two-field Query as the Combo's
RowSource; the Bound Column would be the Test_ID, the Control Source
would be the Test_ID field into which you want to store the data, and
the first visible field in the combo would be the Test_Name. The
Test_Name should certainly NOT be stored in your form's table.

Why the textbox?
Code for combo box:
Private Sub Test_Name_BeforeUpdate(Cancel As Integer)
' Update Test_Id To controls based on value selected in Test_Name combo box.
Me!Test_Id = Me!Test_Name.Column(1)

Note that the Column() property is *zero based*. This will store the
*second* field in the Combo's RowSource query; if that's the TestName
and you're trying to store it in a Text_ID field it will certainly
fail (you can't store text in a number field).
End Sub

Code for the text box:
Private Sub Test_Id_BeforeUpdate(Cancel As Integer)
' Update Test_Name To controls based on value selected in Test_Id combo box.
Me!Test_Name = Me!Test_Id.Column(1)
End Sub

And this makes no sense at ALL. The BeforeUpdate event of the textbox
fires when you have finished *typing* in it; and it looks like you're
trying to update the Combo Box by typing in the Textbox, while at the
same time trying to update the Textbox when you select from the Combo
Box, and that they're both bound to the same field! You're making this
MUCH harder than it is, or I'm completely misunderstanding what you're
attempting!

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top