How do I get Access to identify that a table has no records

G

Guest

I have a form that relies on another table having data before any data can be
put in the original form. (Can't create a patient record unless the doctors
table has some records in it.)

How can I stop a user from trying to create a patient record? What I want to
happen is, that if a user tries to enter a patient's details while the
doctor's table is empty, a message box is displayed and, once the user has
clicked OK, he/she will be reurned to the switchboard (main menu). If the
doctor's table is not empty the form will be displayed to enter the data in
the usual way.

I'm suffering form programmer's block. Presumably, I start with a query
which I have already set up. But where do I go from there? Is it just a
matter of a line or two code in the On Load event?

Any help would be greatly appreciated.

Kind regards

Tony
 
G

Guest

Even if the Doctors table had data, you need to know that it has the correct
Doctor's record in the table. But, to answer your question. Do this in the
Load event of the form:

Dim rst As Recordset
Dim blnNoData As Boolean

Set rst = CurrentDb.OpenRecordset("DoctorTable")
If rst.RecordCount <= 0 Then
blnNoData = True
End If
rst.Close
Set rst = Nothing
If blnNoData Then
MsgBox "No Doctors - I think they are all at the golf club"
DoCmd.Close
End If
 

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