Problem with AfterUpdate event on Combo Boxes

Never Hide

Registered User.
Local time
Today, 22:09
Joined
Dec 22, 2011
Messages
96
I have a form with a few comboboxes that I have created using the combobox wizzard to get data from my database's tables. To, hopefully, make my problem easier to understand I'll just use these simple tables to give you an idea of how I have build my data to work

Address: (AddressName,AddressNumber,PostCode,CityID)
City: (CityID,CityName,CountryID)
Country: (CountryID,CountryName,ContinentID)
Continent: (ContinentID,ContinentName)

In my form I have a combobox for each of my tables and each combobox has all the fields from the responding table so using the "combobox.Column()" i can get the data I want to use in my code.
This is the code in the Address combobox:
Code:
Private Sub comboAddress_AfterUpdate()
Dim cityID as String

cityID=Me.comboAddress.Column(3)

Me.comboCity=DLookup("CityID","City","[CityID]= '" & citryID & "'")

End Sub
This is the code in the City combobox:
Code:
Private Sub comboCity_AfterUpdate()
Dim countryID as String

countryID = Me.comboAddress.Column(3)

Me.comboCountry = DLookup("CountryID","Country","[CountryID]= '" & countryID & "'")

End Sub
And so on as you move up the ladder..
When you select the Address,the responding City is automaticaly selected. The problem is that this is where it stops. And what I mean is that it doesn't give you the responding Country for that City and so on.When I select the Address and I get the City, then I have to manually go and the select the City to get the Country-even if I don't even change the selection of the City,just open the dropdown of the comboCity combobox and immediately close it.

Any ideas about how to solve this problem? Maybe I should be using a different event other than the "AfterUpdate" one?

Any contructive input is greatly appreciated :D
Edit: I forgot to mention that I have also tried using the "On Change" event with the same results
 
Last edited:
For starters, why are you looking up a value you already have? It appears that you look up the ID value you get from the combo column property. In other words, your DLookup is saying "find me the CityID where the CityID equals this CityID that I have".

Does this work in the after update event of the address?

Me.comboCity = Me.comboAddress.Column(3)
Me.comboCountry = Me.comboCity.Column(2)

It's untested, but I'm thinking that when you set the city combo's value, it would have the necessary value for the next combo.
 
The "CityID" in the "Address" table is a foreign key to the "City" table. Look don't get hung up on the names of the fields and the values I use in this particular example. The reason I used this is because in the actual code I use greeklish (greek written with Latin alphabet letters) for the tables,variables and for the comments and could be confusing for those that'll try to read it.
Now about your suggestion, thank you very much for your input but the problem is that the actual code is a bit more complex than this. What I've tried to do he is give you a simplified idea of what I'm trying to do so it would be easier to explain the problem
 
I'm trying to upload a ZIP with my database since I don't yet have 10 posts made but I'm getting this:

Your submission could not be processed because a security token was missing.

If this occurred unexpectedly, please inform the administraror(this is a link) and describe the action you performed before you received this error.
I clicked the link but it doesn't work :(
 
You seem to expect a control's AfterUpdate event to be triggered by assigning a value to the control in code. It isn't.

You need to call all the "downstream" AfterUpdate-code explicitly.

Another unclear thing is using combos for things which aren't selectable. Your Address apparently determines what goes into the remaining controls, and you are running lookups anyway, so why not just have some textboxes.

And I agree with Paul - your example, with using the lookups, does not make much sense as is, since it shows looking up stuff already known.
 
Last edited:
Thank you very muc for you input spikepl,
I see now-from what you and pbaldy say- that my attempt to simplify my idea was poorly thought :D
That is why I tried to upload a copy of my DB so someone could have a look at it but I've run to the problem I mentioned before :( any ideas about it?
 
No.

Did you try Paul's suggestion?
 
Problem sorted out....when you said I should use the AfterUpdate code, that pointed me to a more refined search :D
I've made all the subs public and I just call them at the point of the code I want it to execute :)
Thank you very much fo you help guys :D
 
Glad you got it sorted out.
 

Users who are viewing this thread

Back
Top Bottom