query form

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
 
C

Chegu Tom

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.
 
E

Eric Starn

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
 
C

Chegu Tom

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top