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

Textboxes won't update based on Combobox Value 1

Status
Not open for further replies.

Faded

Programmer
Feb 6, 2002
78
CA
Hi.

I have a combobox that gets it's values from a query. Then upon updating the combobox, two textboxes should update their values based on what is selected.

Here is the query called qryRequestor (simplified):

SELECT alias, dept, phone
FROM list

Then in the Combobox properties, I have row source type set to Query/Table and row source set to qryRequestor

In the cboRequestor_AfterUpdate() event in VBA code, I have the following:

Me!txtDepartment = Me![cboRequestor].Column(1)
Me!txtPhone = Me![cboRequestor].??????

where txtDepartment and txtPhone are the textboxes that need to be updated. The txtDepartment on updates just fine, but I can't get the txtPhone one to update. All of the properties are identical, yet it just won't work. What do I replace the question marks with to get the phone field inserted into the textbox?

Thanks in advance.
Faded

 
Faded, I'm only a tech here so taking a shot in the dark. Let's say the combobox can be "bound" to both Column 1 and Column 2. Then I couldn't help you, because as you said it should work. But I've never had a combobox bound to more than one field, primarily because I've lived without that feature...but I seem to remember something along the way in which both columns could be captured at one time...sort of like in your example above, where Column(1) and Column(2) should be recognized. Maybe it should be Column(0) and Column(1)..don't know.

If I were faced with this problem I'd probably put in the "On Current" event of the form the code which would populate your txtPhone box. Using a DLookup line in the code I'd use your Column(1) value which comes back ok, and then look up the value for txtPhone and set it to that value..

Me.txtPHone = DLookUp("...........and so on)

Just an idea. I am interested in finding an argument for grabing both Columns, or multiple columns from a combo box at one time so maybe someone will share that with us.
 
How about Me!txtPhone = Me![cboRequestor].column(0), where column(0) is acutally the first column and column(1) is the second?
 
Thanks to all of you who gave advice. In the end It was that the Column Count property was set to 1. As soon as I changed it to 2 the txtPhone value was set to the phone number.

The code now reads:

Me!txtDepartment = Me![cboRequestor].Column(1)
Me!txtPhone = Me![cboRequestor].(2)

and the Column Count Property is set to 2.

Thanks to all of you who helped!

Faded
 
Excellent example Faded

So, if you create a combobox or listbox with say, 3 columns, set your "column count" and then

Me.txtA = Me.cmbA.Column(1)
Me.txtB = Me.cmbA.Column(2)
Me.txtC = Me.cmbA.Column(3)

thereby capturing all three values brought in by an underlying SQL or query...

Useful technique...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top