PDA

View Full Version : Solved: Not Solved:It looked like it was working I want a combo box to limit a combo box



hatched850
11-14-2006, 03:11 PM
Solved: I want a combo box to limit a combo box
In a form I have a combo box to select a county the next combo box is the city. I have a table with the counties and their cities. I want to make the city combo box in my form list only the cities for the county that was already selected. Does this make sense?

:help

as always you guys are the greatest!!


Hatched850 :cloud9:


Local Time: 05:09 PM
Local Date: 11-14-2006
Location: http://www.vbaexpress.com/forum/images/flags/United%20States%203D.gif http://www.vbaexpress.com/forum/images/flags/states/Florida%203D.gif

http://www.vbaexpress.com/forum/images/buttons/quote.gif (http://www.vbaexpress.com/forum/newreply.php?do=newreply&p=79521) http://www.vbaexpress.com/forum/images/buttons/top.gif (http://www.vbaexpress.com/forum/showthread.php?t=10198#top) hatched850View Public Profile (http://www.vbaexpress.com/forum/member.php?u=2368)Send a private message to hatched850 (http://www.vbaexpress.com/forum/private.php?do=newpm&u=2368)Find More Posts by hatched850 (http://www.vbaexpress.com/forum/search.php?do=finduser&u=2368)


http://www.vbaexpress.com/forum/images/statusicon/post_new.gif Today, 06:02 PM #2 (http://www.vbaexpress.com/forum/showpost.php?p=79529&postcount=2) hatched850 (http://www.vbaexpress.com/forum/member.php?u=2368) vbmenu_register("postmenu_79529", true);

http://www.vbaexpress.com/forum/images/statusicon/user_online.gif VBAX Regular (http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_faq_user_ranks)

Joined: May 2005
Posts: 21
Kb Entries: 0 (http://www.vbaexpress.com/kb)

I fixed it myself!!!! Are you guys not proud. Right clicked on property field for the look up I was trying to limit and went to the query and fixed set the criteria to [Forms]![community colleges]![District]. It works great.


Hatched850 :cloud9:


Local Time: 05:09 PM
Local Date: 11-14-2006
Location: http://www.vbaexpress.com/forum/images/flags/United%20States%203D.gif http://www.vbaexpress.com/forum/images/flags/states/Florida%203D.gif

hatched850
11-14-2006, 03:30 PM
but only if I reopen the form everytime. What am i doing wrong.

Saurabhk
11-14-2006, 07:09 PM
Try this code. Combo0 contains the country name

Private Sub Combo0_Change()
country = Combo0.Value
strSQL = " SELECT CITY_NAME FROM CITY WHERE COUNTRY_NAME ='" & country & "';"
Me.Combo2.RowSource = strSQL
Me.Combo2.RowSourceType = "Table/Query"
Me.Combo2.BoundColumn = 1
End Sub
Private Sub Combo0_Click()
Combo2.Value = Null
End Sub

OBP
11-15-2006, 04:02 AM
Hatched, is it solved or not?

hatched850
11-15-2006, 06:39 AM
Not

OBP
11-15-2006, 09:36 AM
Can you post a copy for us to look at then?

Imdabaum
11-15-2006, 01:33 PM
Hatched, did you try Saurabhk's code in the AfterUpdate event? I just wrote similar code for the real estate department that I work for so they can manage properties in different countries, states, and cities.

Try Me.Combo2.Requery after you set the RowSource.

Saurabhk
11-15-2006, 04:28 PM
Hi Hatched,

Did you try the code I submitted?
What seems to be the problem with that one?

hatched850
11-20-2006, 12:55 PM
Sorry guys I am just not very good at this. I appreciate your help. I have attached the data base and where I have been trying to make the codes you sent me work. Unfortuneatly I got pulled from this project and asked to work on something else last week. I am finally working on get this up and running. I have attached the data base I am trying to create. Thank you again you guys are the best.

Debbie:banghead:

OBP
11-20-2006, 01:49 PM
Debbie, I am not surprised that you couldn't get them to work. Combo Look-up fields in the table are easy to produce but not good programming.
They were messing up the selection process.
It is much better to base your Combo box on the Form and get it's data from a query.
The form is now working OK.
Check the Query "Select City" to se how it works.
The combo is refreshed by VB code when ther Record or the District Combo change.

hatched850
11-20-2006, 02:09 PM
You are WONDERFUL. I WAS GOING CRAZEY TRYING TO GET IT TO WORK.

dEBBIE

OBP
11-21-2006, 03:21 AM
Debbie, if you need any more help let us know.