Combo box Requery

Sticky99

Registered User.
Local time
Today, 13:17
Joined
Nov 9, 2019
Messages
61
Hi Guys, sorry if this is a dumb question, but here goes.

I have a form with a Combobox which populates a customers address:

Private Sub cboCustomerAddress_Change()
Me.Address1.Value = Me.cboCustomerAddress.Column(2)
Me.Address2.Value = Me.cboCustomerAddress.Column(3)
Me.Town.Value = Me.cboCustomerAddress.Column(4)
Me.Postcode.Value = Me.cboCustomerAddress.Column(5)
Me.Country.Value = Me.cboCustomerAddress.Column(6)
End Sub

I also have a button that opens another form to add new addresses, could anyone tell me how to requery the Combobox to show newly added addresses when I save the "New Address" form. I've tried a Requery Macro with Forms!frmMainForm!cboCustomerAddress which returns an error "There is no field named Forms!frmMainForm!cboCustomerAddress in the current record."

Grateful for any help.

Thanks
 
I'm not sure this is directly your issue, but you may find it helpful at least a good reference.
You may also try Me.requery.
 
I also have a button that opens another form to add new addresses, could anyone tell me how to requery the Combobox to show newly added addresses when I save the "New Address" form.
Here is the issue. If you have code that pops up a form to enter data followed by code to requery then what happens is the form pops open and the next line of code to requery executes. In order to wait until the pop up form closes you must open the pop up ACDIALOG in the docmd.openform method. If not you will requery the combobox before any new records are added and thus nothing new is seen.
 
sticky99, you are missing 1 thing on your macro.
this will be your macro (on After Update Event):
Code:
SelectObject
    Object Type    Form
    Object Name    frmMainForm
     In Database Window       No   
Requery
    Control Name    [cboCustomerAddress]
 
Hi Guys,

Thanks to you all for your inputs, have now resolved the issue.

I used Forms!frmMainForm!cboCustomerAddress.Requery on close, this seemed to work.
Again thanks guys. :)
 
Just as a side note I would recommend you move your code from the Change event of the combo (which fires for every keystroke) to the AfterUpdate event.
Cheers,
 
Just as a side note I would recommend you move your code from the Change event of the combo (which fires for every keystroke) to the AfterUpdate event.
Cheers,
Thanks for the tip.
 
But, you probably don't need to store the address twice anyway. If you simply store the FK to the address, a query with a left-join will be able to pick up the address attributes when you need them.
 

Users who are viewing this thread

Back
Top Bottom