Combo Box Requery Not Working  | Newbie | | Join Date: Mar 2007 Location: Vancouver, Canada
Posts: 26
| | |
Hi,
I have a combo box on a form with a list of cities in it based on a single field city table. I also have a command button on this form that opens up another form that allows the user to enter in new cities to the city table. Now, after i dd new cities to the table, and when I go back to drop down the city combo box, the new cities I added aren't in the list. I researched tutorials and found that combo boxes need to be requeried in order to reflect the updated table. Here is the line of code that I put in the event procedure for the On Click event of the combo box:
Private Sub cboCity_Click()
Me.cboCity.Requery
End Sub
I also tried:
Me!cboCity.Requery
but this line of code doesn't work either. I get no code errors, but it doesn't requery.
Now I tried this in the After Update event as well with no luck. The table just doesn't want to requery itself after I've modified the city table. The only way I can get it to reflect the changes is if I close down the form completely and restart it, which is not something I want to do every time I add a new city.
Any suggestions?
Thank you,
Wayne.
|  | Expert | | Join Date: Jan 2007 Location: California
Posts: 3,835
| | | re: Combo Box Requery Not Working Quote:
Originally Posted by waynetheengineer Hi,
I have a combo box on a form with a list of cities in it based on a single field city table. I also have a command button on this form that opens up another form that allows the user to enter in new cities to the city table. Now, after i dd new cities to the table, and when I go back to drop down the city combo box, the new cities I added aren't in the list. I researched tutorials and found that combo boxes need to be requeried in order to reflect the updated table. Here is the line of code that I put in the event procedure for the On Click event of the combo box:
Private Sub cboCity_Click()
Me.cboCity.Requery
End Sub
I also tried:
Me!cboCity.Requery
but this line of code doesn't work either. I get no code errors, but it doesn't requery.
Now I tried this in the After Update event as well with no luck. The table just doesn't want to requery itself after I've modified the city table. The only way I can get it to reflect the changes is if I close down the form completely and restart it, which is not something I want to do every time I add a new city.
Any suggestions?
Thank you,
Wayne. I've come across this too but I don't know why it won't work. So I usually end up using a Me.Refresh.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,886
| | | re: Combo Box Requery Not Working
In the On Close event of the Add Cities form is when you need to requery the combobox. -
Private Sub Form_Close()
-
-
Forms![FirstFormName]![cboCity].Requery
-
-
End Sub
Mary
|  | Newbie | | Join Date: Mar 2007 Location: Vancouver, Canada
Posts: 26
| | | re: Combo Box Requery Not Working
Hi Rabbit,
Yeah it is strange. I even tried your Me.Refresh in my code. I put in in my click event on my combo box so when I click to open the combo list options, it should refresh the list immediately. hmmm, what event are you linking your Me.Refresh to?
Wayne. Quote:
Originally Posted by Rabbit I've come across this too but I don't know why it won't work. So I usually end up using a Me.Refresh. |  | Expert | | Join Date: Jan 2007 Location: California
Posts: 3,835
| | | re: Combo Box Requery Not Working Quote:
Originally Posted by waynetheengineer Hi Rabbit,
Yeah it is strange. I even tried your Me.Refresh in my code. I put in in my click event on my combo box so when I click to open the combo list options, it should refresh the list immediately. hmmm, what event are you linking your Me.Refresh to?
Wayne. I put it right after the code that changes the listbox.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,886
| | | re: Combo Box Requery Not Working
Wayne you are using two different forms so the Me.Refresh won't work as you are refreshing the wrong form. Have you tried the code I gave you in post #3?
|  | Newbie | | Join Date: Mar 2007 Location: Vancouver, Canada
Posts: 26
| | | re: Combo Box Requery Not Working
Again! Mary, you are two for two with my postings. Your code works perfectly. I should alert Rabbit of this code.
Thank you! :)
Best regards,
Wayne. Quote:
Originally Posted by mmccarthy In the On Close event of the Add Cities form is when you need to requery the combobox. -
Private Sub Form_Close()
-
-
Forms![FirstFormName]![cboCity].Requery
-
-
End Sub
Mary |  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,886
| | | re: Combo Box Requery Not Working
No problem.
|  | Newbie | | Join Date: Mar 2007 Location: Vancouver, Canada
Posts: 26
| | | re: Combo Box Requery Not Working
I replied to your last message as you made this message, so yes it does work :) And what are you doing up so early in Ireland, get back to bed! Quote:
Originally Posted by mmccarthy Wayne you are using two different forms so the Me.Refresh won't work as you are refreshing the wrong form. Have you tried the code I gave you in post #3? |  | Newbie | | Join Date: Mar 2007 Location: Vancouver, Canada
Posts: 26
| | | re: Combo Box Requery Not Working
Check out Mary's solution, it works great.
Thanks again,
Wayne. Quote:
Originally Posted by Rabbit I put it right after the code that changes the listbox. |  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,886
| | | re: Combo Box Requery Not Working Quote:
Originally Posted by waynetheengineer I replied to your last message as you made this message, so yes it does work :) And what are you doing up so early in Ireland, get back to bed! Haven't been to bed yet. I'm a vampire. I work through the night and sleep during the day. When I sleep that is. :rolleyes:
|  | Expert | | Join Date: Jan 2007 Location: California
Posts: 3,835
| | | re: Combo Box Requery Not Working Quote:
Originally Posted by waynetheengineer Check out Mary's solution, it works great.
Thanks again,
Wayne. I've already tried her solution. That and my listbox is on the same form that's calling the sub.
|  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|