Combo box requery

  • Thread starter Thread starter Corinne
  • Start date Start date
C

Corinne

I have a form that has a combo box to look up the name of
the record I wish to find. If I add a new record to the
form the name does not appear in the combo box until I
close the form and re-open it. I am sure I have seen
somewhere that it is possible to do a requery to save
having to close the form. I have search for days and
unable find what I am looking for. I am quite new to this
and will need specific instructions as to where to put
the code in the properties if anyone does have an answer
for me.
Thanks in advance.
 
Corinne:
On the After Update property of the Form

Private Sub Form_AfterUpdate()
Me!MyComboBox.Requery
End Sub

Also, if you want it to not display any longer a record just deleted

Private Sub Form_Delete(Cancel As Integer)
Me!MyComboBox.Requery
End Sub

Phil

I have a form that has a combo box to look up the name of
the record I wish to find. If I add a new record to the
form the name does not appear in the combo box until I
close the form and re-open it. I am sure I have seen
somewhere that it is possible to do a requery to save
having to close the form. I have search for days and
unable find what I am looking for. I am quite new to this
and will need specific instructions as to where to put
the code in the properties if anyone does have an answer
for me.
Thanks in advance.
 
Corinne,
On the AfterUpdate event for your [CustName] (or whatever field you want
to initiate the Requery from), place this code...
Refresh
Me.cboMyCombo.Requery
The Refresh will update the record, and the Requery will add the name to
the combo box.
 
Since I often send users to related forms to add new data, I prefer to
requery when the combo in question gets focus, which ensures the update when
the user returns to the combo's form.

For example,

Private Sub cboWhatever_GotFocus()
Me.cboWhatever.Requery
End Sub

Don't forget your error handling!

D
 
Back
Top