Requery comboboxes

Never Hide

Registered User.
Local time
Today, 08:26
Joined
Dec 22, 2011
Messages
96
Update different combo boxes based on what you select

Hi everyone, I'm new here and i hope I can explain my problem clearly enough fo everyone to understand.
I have a database with a few tables with Villages, Cities, States etc.(kind of states,I'm from Greece and I don't know all the equivalent terms but that's not the point:) )
To simplify things I'll give an example with the City and State Tables :
State(id, Name)
City(id, Name, Parent_id, LAT, LON)
"Parent_id" is a Foreign Key that refairs to the State each city belongs to. The general idea for the tables is (id,name,paent_id) where parent_id refers to the "higher [FONT=&quot]authority"(I hope that's not confusing:)) for each case.
I have created a form in which I display in textboxes the LAT/LON info for each city.[/FONT][FONT=&quot]
I have also created another combox "cboxState", which is linked to the State table and when i chose a State it limits the options of the cboxCity so you only select cities from that state.
I have may more tables in my database and I use the same idea in the form to move futher down the hierarchy

My Problems now:
Numbe1:
(For the sake of simplicity I'll refer to only 2 tables)

I would like to have the option to select a City and that to limit the displayed options of the cboxState to the State the selected city belongs to BUT without disabling the option to select a State and see the cities in that state.
So basically I want to be able to requery any combox depending on what choice i make
Numbe2:
Some cities "belong" directly to a state-if u will- and not to a municipality which in its turn "belong" to a state so in the "Parent_id" of the "City" table ot all recods have the same "type" of id. By that I mean that a City that "belongs" directly to a state will have a Parent_id which only has 4 numbers.A city that "belongs" to a municipality has a Parent_id with 6 numbers, and so on. So what I want to do is this: when the Parent_id of a city that is selected is 4 numbers long,cboxCity has to requery the cboxState.If it's 6 numbers long i want it to requery the cboxMunicipality.
What I've tried in the AfterUpdate even of cboxCity is this:
By the way I have set "Parent_id" as a text field
[/FONT]
Code:
Private Sub cboxCity_AfterUpdate()
  If Len(cboxCity.Column(7))=4 Then
   Me.cboxState.Requery
  ElseIf Len(cboxCity.Column(7))=6 Then
   Me.cboxMunicipality.Requery
  End IF

End Sub
Column(7) (starting the count from Column(0) for the 1st column)is the Column of the cboxCity that contains the "Parent_id".
Also at the "Bound Column" property I've chosen "0"


[FONT=&quot] Unfortunately that doesn't work :(

Any suggestions/ideas are greatly [/FONT]appreciated

P.S. If you notice in some words missing "R"s ,excuse my stupid keyboard:D
 
Last edited:
Thankk you for the quick repley, I didn't have time to watch the videos yesterday so I watched them today. But I can allready do what the videos mention.
Maybe I can better explain what I need now, using the example of this video. With this example you select a Region and then the options of the Locations in the cmblocation are limited according to you selected Region. And then same happens for the LocNumber according to the selected Location.What I'd like to accomplish :
For example you don't know the Region of a Location so your 1st selection is from the Location combo box and then the Region combo box will have the option to select the Region that you selected Location belongs to, and at the LocNumber you still get all the options for the selected Location. Or if your 1st choice is fom the LocNumber you get the according location in the Location combobox and the accoding region in the Region combo box. And of course to still be able to use the original order ( Select Region->Select Location->Select LocNumber). So in a way, to be able to dynamicly chose which combo boxes has to be updated and in what order( I hope this last sentence makes some kind of sence)
 

Users who are viewing this thread

Back
Top Bottom