469,330 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Combo Box Requery Not Working

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.
Mar 29 '07 #1
12 19692
Rabbit
12,516 Expert Mod 8TB
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.
Mar 29 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
In the On Close event of the Add Cities form is when you need to requery the combobox.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.  
  3.    Forms![FirstFormName]![cboCity].Requery
  4.  
  5. End Sub
Mary
Mar 29 '07 #3
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've come across this too but I don't know why it won't work. So I usually end up using a Me.Refresh.
Mar 29 '07 #4
Rabbit
12,516 Expert Mod 8TB
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.
Mar 29 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
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?
Mar 29 '07 #6
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.

In the On Close event of the Add Cities form is when you need to requery the combobox.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.  
  3.    Forms![FirstFormName]![cboCity].Requery
  4.  
  5. End Sub
Mary
Mar 29 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
No problem.
Mar 29 '07 #8
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!



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?
Mar 29 '07 #9
Check out Mary's solution, it works great.

Thanks again,

Wayne.

I put it right after the code that changes the listbox.
Mar 29 '07 #10
MMcCarthy
14,534 Expert Mod 8TB
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:
Mar 29 '07 #11
Rabbit
12,516 Expert Mod 8TB
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.
Mar 29 '07 #12
I just encountered the same problem. In my case, I change my values and save it to the records in one form (sort of a dialog box), then view the queried results in another form (stays open while I'm changing data through my dialog box).

Expand|Select|Wrap|Line Numbers
  1. RefreshForm.Requery
  2.  
I've tried the following suggestions:

Expand|Select|Wrap|Line Numbers
  1. Application.CurrentDb.QueryDefs.Refresh
  2. RefreshForm.Requery
  3.  
Expand|Select|Wrap|Line Numbers
  1. RefreshForm.Refresh
  2. RefreshForm.Requery
  3.  
However, none of them worked. The only thing that worked for me is to re-specify the form filter and turn it on.

Expand|Select|Wrap|Line Numbers
  1. RefreshForm.Filter = Filters
  2. RefreshForm.FilterOn = True
  3.  
Where RefreshForm is a Public Object variable set to the Form I want to update, and Filters is a Public String in which I stored the filter on which my Form Query is based. Maybe a parallel method may work--try re-specifying the RowSource property of the ComboBox within cboCity_Click().

Regards.
Jan 17 '13 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Sean | last post: by
1 post views Thread by Matt | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.