Solved Synch combos not working.

slharman1

Member
Local time
Today, 12:47
Joined
Mar 8, 2021
Messages
483
I am so frustrated!
I can not get my second combo box to populate with data. Here is what I have:

MS access 2016

Private Sub CustID2_AfterUpdate()

Me.cboCustConID2.RowSource = "SELECT Contact FROM" & _
" tblCustomerContacts WHERE CustomerID = " & Me.cboCustID2 & _
" ORDER BY Contact"

Me.cboCustConID2 = Me.cboCustConID2.ItemData(0)


'''If IsNull(Me.cboCustConID2.Value) Then
'DoCmd.OpenForm "frmEditCustomers", , , "CustomerID =" & cboCustID2.Value
'End If

End Sub
 
Looks like you're trying to grab a value from cboCustID2 when the user just updated CustID2 (not the combobox).
 
Looks like you're trying to grab a value from cboCustID2 when the user just updated CustID2 (not the combobox).
Hmm...not sure which line of code you are referring to. MY first combo box is populated correctly
 
Last edited:
Hmm...not sure which line of code you are referring to. MY first combo box is populated correctly
The first part of your code has this:
Private Sub CustID2_AfterUpdate()
That means the code runs after the user updated the CustID2 control.

But, in your code, you have this:
...WHERE CustomerID = " & Me.cboCustID2
So, the code is located in CustID2, but you're trying to use the value from cboCustID2 in your code.

Hope that makes sense...
 
The first part of your code has this:

That means the code runs after the user updated the CustID2 control.

But, in your code, you have this:

So, the code is located in CustID2, but you're trying to use the value from cboCustID2 in your code.

Hope that makes sense...
Thanks, I think I get it - the sub name is wrong.
Should be like this?

Private Sub cboCustID2_AfterUpdate()

Me.cboCustConID2.RowSource = "SELECT Contact FROM" & _
" tblCustomerContacts WHERE CustomerID = " & Me.cboCustID2 & _
" ORDER BY Contact"

Me.cboCustConID2 = Me.cboCustConID2.ItemData(0)



'If IsNull(Me.cboCustConID2.Value) Then
'DoCmd.OpenForm "frmEditCustomers", , , "CustomerID =" & cboCustID2.Value
'End If

End Sub
 
The first part of your code has this:

That means the code runs after the user updated the CustID2 control.

But, in your code, you have this:

So, the code is located in CustID2, but you're trying to use the value from cboCustID2 in your code.

Hope that makes sense...
Still doesn't work - I can't figure out what I am doing wrong.
 
Do you get a value from your first combo?

Think you better post your file!
 
Still doesn't work - I can't figure out what I am doing wrong.
Hi. Since we can't see your form, we can't really tell why it's not working. I'm not sure if you're using the correct event or the wrong control. If you can post a sample copy of your db with test data, we could probably tell you how to make it work. Just a thought...
 
To all. Thanks for all the help. Once I searched for how to accomplish this online without using Microsoft’s example everything worked perfectly.
 
To all. Thanks for all the help. Once I searched for how to accomplish this online without using Microsoft’s example everything worked perfectly.
Hi. Glad to hear you got it sorted out. Cheers!
 
Hi. Glad to hear you got it sorted out. Cheers!
Yes sir. 4 hours of having fun wrong and 5 minutes of writing code correctly. Is the Microsoft cab page current as far as cab code, syntax, and examples?
 

Users who are viewing this thread

Back
Top Bottom