No Data for Form

R

Rillo

I have a data entry form containing a reference and other fields. When the
Lost Focus event occurs on the reference field, a macro is invoked that
displays a second form containing the reference and a name. The second form
is based on a query that finds a record with a matching reference. The
purpose is to allow the user to check the name before proceeding.
When the user closes the second form with a command button, the first form
is redisplayed.
This process works fine until the query produces no matching records, in
which case a completely blank form is displayed.
How can I introduce a “no data†condition into the macro that displays the
second form, so that, say, a message could be displayed instead of a blank
form?

I would prefer to work within the macro, rather than use code, if possible.
 
R

Rillo

This is now working - thanks for your help.


Chris O'C via AccessMonster.com said:
Macros aren't capable of using even simple logic to make decisions. Macros
can only execute step-wise instructions. You have to use VBA code. To make
it as simple as possible:

In the second form's properties, find the Open event. Click on the combo box
next to it and select [Event Procedure]. Click on the 3 dots on the right of
the combo box to go to the code editor. Paste this VBA code inside the
procedure (that's where the cursor is). Save and compile the code. (Menu:
Debug > Compile yourDBname.)

If (Me.RecordsetClone.RecordCount) = 0 Then
MsgBox "There is no match."
Cancel = True
End If


Chris
Microsoft MVP

How can I introduce a “no data†condition into the macro that displays the
second form, so that, say, a message could be displayed instead of a blank
form?

I would prefer to work within the macro, rather than use code, if possible.
 

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