query form

  • Thread starter Thread starter Eric Starn
  • Start date Start date
E

Eric Starn

I have a form that opens when you run a query for an employee name. It does
exactly what it is suppose to do. It displays all information that I have
requested. The problem I am having is when I enter a name of an employee that
is not in the database the form comes back as a grayed out box. Is there any
way to set the form or query to prompt the user that the name is not in the
database and allow the user to run the query again.

Eric
 
Check to see if record exist before you open the form.


If you are using a command button to open your form containing code like
the following to open your form to the correct records

docmd.OpenForm "yourForm", , , "EmployeeName='" & txtEmployeeName & "'"


Before you open the form check the table to see if the employeename exists.
use Dcount or Dlookup

if Dcount("EmployeeName","EmployeeTable","EmployeeName='" & txtEmployeeName
& "'")=0 then
msgbox txtEmployeename & " Doesn't exist"
else
docmd.OpenForm "yourForm", , , "EmployeeName='" & txtEmployeeName & "'"
Endif


Replace the names I used with you own.
 
Thanks for the help

Question, where do I put that code?
In the "OnClick" of the command button or some where else.
Also, I already have the query running in the OnClick spot. Is this going to
be a problem?

Eric
 
Where do you have the code or macro to open your form?

That code (whereever it is) should be part of an 'IF" statement (as I showed
below)

I suspect it is in the onclick event of your button. Change that. Put it
in the 'If' statemenmt.
 
Back
Top