Issue populating combobox

molloyjh

Registered User.
Local time
Today, 14:23
Joined
Jun 23, 2009
Messages
13
Hi all,

I'm having a very strange issue with populating a combobox in access. It's a fairly straight forward scenario. I have a form with a number of fields on it. When I select a value from a combobox I want it to update a number of other fields, specifically 2 other combobox's and a text box.

It should be straightforward but no value appears in the 2nd combobox despite the fact that a quick MsgBox to test it's value displays the value I would expect to see. So while the MsgBox says there is a value nothing actually appears.

Any ideas (and no the text colour isn't white or anything like that)???

The code is as follows:

Private Sub ComboBox1_AfterUpdate()

' This code will search the records on the form that
' match the value in Combobox1.
' This in turn updates Textbox1 with the corresponding
' value from the table.
Me.Combobox2.SetFocus
DoCmd.FindRecord Me.Combobox1

' This will set the value in Combobox2 equal to the
' value in Textbox1 and moves the focus to Combobox 2
Me.Combobox2 = Me.Textbox1
Me.Combobx2.SetFocus

' This MsgBox is a test of the value in Combobox2
MsgBox "Value in Combobox2 = " & Me.Combobox2
End Sub
 
You may want to watch the video tutorials at
http://www.datapigtechnologies.com/flashfiles/combobox1.html
http://www.datapigtechnologies.com/flashfiles/combobox2.html

or lookup information on Cascading comboboxes

Sorry jdraw, I probably should have said above that when I click on the the dropdown I do get the correct values in the dropdown itself. That part is not a problem. I also realised my code was wrong in the OP. It should be:

Private Sub ComboBox1_AfterUpdate()
' This code will search the records on the form that
' match the value in Combobox1.
' This in turn updates Textbox1 with the corresponding
' value from the table.
Me.Combobox2.SetFocus
DoCmd.FindRecord Me.Combobox1

' This will set the value in Combobox3 equal to the
' value in Textbox1 and moves the focus to Combobox 3
Me.Combobox3 = Me.Textbox1
Me.Combobx3.SetFocus

' This MsgBox is a test of the value in Combobox2
MsgBox "Value in Combobox3 = " & Me.Combobox3
End Sub

I basically have a form that has 2 comboboxes that have no control source and a number of fields that do. I'm using these comboboxes to search the records within the form.

Combobox1 & 3 have no ControlSource

Combobox1 & 2 have the same RowSource
Textbox1 and Combobox3 have the same RowSource

When I select combobox1 I want that to return the first matching row within the data. It does this correctly and combobox2 and textbox1 are updated as expected. The RowSource for combobox3 is also modified correctly and the list of available values is correct.

The code should also set the selected value in combobox3 to match what is in textbox1. The MsgBox I used to debug the code suggests that the selected value is indeed the same as the textbox, yet no selected value appears.

Hope this makes sense!!!

Thanks,
J.
 

Users who are viewing this thread

Back
Top Bottom