Using a combobox to pull up a record

  • Thread starter Thread starter chang
  • Start date Start date
C

chang

I have set up a combobox to pull up a record, but when i enter new records
the combobox doesnt update, how can i get it to constantly update?
 
Hi,

This could be kind of involved depending on whether
you've ever played with VBA. But, this is how I'd do
it...

I'm imagining that you're probably pulling up something
like a customer order number via the combo box. I'd set
the recordsource of the combobox to a query something
like:
"SELECT CustomerOrderNumber FROM tblCustomerOrders ORDER
BY CustomerOrderNumber"

This will populate the combo box with the latest set of
CustomerOrder numbers in ascending order everytime you
open the form.

Now, if you're adding orders through the same form that
this combo box is on, you might need to add a short
snippet of VBA code somewhere in the process to force the
combobox to requery it's recordsource every time you add
a new record.

On the form properties, under events, look for the event
called AfterInsert. Click on the three dots and choose
Event Builder. This will take you to the VBA editor and
your cursor will be in a section of code that looks
something like

Private Sub Form_AfterInsert()
 
Bah, I hate web interfaces....sent by accident.

So we were where? Your cursor should be in a block of
code that looks sort of like this:

Private Sub Form_OnAfterInsert()

'Start Entering your code here. Omit this line.
Me.cboxCustomerOrderNumber.Requery


End Sub


Save the file and close the VBA editor. Now, if
everything's cool, the CustomerOrderNumber combo box
should be requeried to include the Customer Order Number
of the order you just entered.

If you've never poked around in the VBA editor, try this
out on a copy of your form before you put it in the real
thing. Poking around in there is not as intimidating as
it looks, but it's still a good idea to work on a copy
when you're doing new things.

Good Luck,

Fred D
 
Back
Top