Using a Message Box to open a form.

  • Thread starter Thread starter Mike Wilson
  • Start date Start date
M

Mike Wilson

Help please

I want to use a message box to hold a search criteria and open a form
to display any matching record or records.

The code that I am trying to adapt is

DoCmd.OpenForm "AltAddress"
QryFld = "Company"
Me.Filter = "[Company] Like '*" & InputBox("Enter Company") & "*'"
Me.FilterOn = True

The message box is activated on the onclick event for a text box called
company.

All I manage to do is to open the AltAddress form displaying all record.

Any guidance would be gratefully appreciated

Thanks
 
Re: Using a Message Box to open a form
Mike

I suspect you need to "apply" the filter too.

--
Good luck

Jeff Boyce
<Access MVP>


Thanks for the response Jeff

I might be getting this wrong but I tried adding
"DoCmd.ApplyFilter Me.FilterOn"

as the last line in the code, previously.. but still ended
up displaying all the records.

Is the code I am using in the wrong order ?


Thanks
Mike
 
A MessageBox is intended only for _showing_ data to the user, and,
optionally, accepting one of certain predefined responses. It isn't suitable
for the purpose you describe. An Input Box can be used to allow the user to
enter data, but it isn't very "user-friendly"

If you wish to use a Form to accept Search criteria (a Combo Box is much
more user friendly than a text box -- you can use a Row Source that includes
all the valid search values, so the user can either type or choose) then you
can do what you want... either use the WhereCondition argument of
DoCmd.OpenForm, or create a complete SQL statement including the WHERE,
which you use in the newly-opened Form's Open event to replace the Form's
RecordSource.

Larry Linson
Microsoft Access MVP
 
Back
Top