Connecting Tech Pros Worldwide Forums | Help | Site Map

Combo Box Requery Not Working

waynetheengineer's Avatar
Newbie
 
Join Date: Mar 2007
Location: Vancouver, Canada
Posts: 26
#1: Mar 29 '07
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.

Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#2: Mar 29 '07

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.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#3: Mar 29 '07

re: Combo Box Requery Not Working


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
waynetheengineer's Avatar
Newbie
 
Join Date: Mar 2007
Location: Vancouver, Canada
Posts: 26
#4: Mar 29 '07

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.

Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#5: Mar 29 '07

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.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#6: Mar 29 '07

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?
waynetheengineer's Avatar
Newbie
 
Join Date: Mar 2007
Location: Vancouver, Canada
Posts: 26
#7: Mar 29 '07

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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.  
  3.    Forms![FirstFormName]![cboCity].Requery
  4.  
  5. End Sub
Mary

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#8: Mar 29 '07

re: Combo Box Requery Not Working


No problem.
waynetheengineer's Avatar
Newbie
 
Join Date: Mar 2007
Location: Vancouver, Canada
Posts: 26
#9: Mar 29 '07

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?

waynetheengineer's Avatar
Newbie
 
Join Date: Mar 2007
Location: Vancouver, Canada
Posts: 26
#10: Mar 29 '07

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.

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#11: Mar 29 '07

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:
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#12: Mar 29 '07

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.
Reply