Combo box Requery (1 Viewer)

Sticky99

Registered User.
Local time
Today, 04:24
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
 

bob fitz

AWF VIP
Local time
Today, 12:24
Joined
May 23, 2011
Messages
4,719
Try:
Forms!frmMainForm.cboCustomerAddress
(Replace the ! with .)
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:24
Joined
Jan 23, 2006
Messages
15,379
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:24
Joined
May 21, 2018
Messages
8,525
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:24
Joined
May 7, 2009
Messages
19,233
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]
 

Sticky99

Registered User.
Local time
Today, 04:24
Joined
Nov 9, 2019
Messages
61
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. :)
 

bastanu

AWF VIP
Local time
Today, 04:24
Joined
Apr 13, 2010
Messages
1,402
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,
 

Sticky99

Registered User.
Local time
Today, 04:24
Joined
Nov 9, 2019
Messages
61
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:24
Joined
Feb 19, 2002
Messages
43,223
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

Top Bottom