Form and filters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I know this is a very simple question for most people, but I am having so
much trouble. I have a form that is pulling data from a table. The form
will be used to update the table. I have a column called store_number, and
when the user opens the form, I would like for the form to prompt for the
store number and only show the records for that store. How can I do this?
Thank you so very much.
 
you can set a filter on the form, in the form's Open event procedure or Load
event procedure, as

Me.Filter = "store_number = " & InputBox("Enter the store number.")
Me.FilterOn = True

the above syntax assumes that the store_number field is a number data type.
if it's a text field, use

"store_number = '" & InputBox("Enter the store number.") & "'"

you need to also handle situations where the user clicks Cancel in the
InputBox, or clicks OK without entering a store number, or enters a number
that doesn't exist.

if you're opening the form from another form, consider skipping the above
solution, and instead adding a combobox to the first form, that lists all
the store numbers. then add a WHERE condition to the OpenForm macro, as

store_number = [combobox name]

or OpenForm VBA code, as

"store_number = " & Me!comboboxname

hth
 
Back
Top