check query prior to opening form? (1 Viewer)

SuttonWillow

New member
Local time
Today, 23:37
Joined
Apr 3, 2021
Messages
1
I have a problem that I think I have a solution to but don’t know how to write the code for it.

I have a button that opens a form, on this form there is a combo box that has a query attached to it, the number of records in this query can change and can return no results which is what it is designed to do, what I would like to do is if the query is empty to inform the user when he clicks on the button, that the combo box is empty, and not open the form.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:07
Joined
Oct 29, 2018
Messages
21,358
Hi. Welcome to AWF!

Can you use DCount() to check if the query is empty or not?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:07
Joined
May 7, 2009
Messages
19,169
Dejavu?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:07
Joined
Feb 28, 2001
Messages
26,999
If the button opens a form, by implication that button is itself on a form, which is good. Because in that context, you can run a "button_ONCLICK" routine so that before you open the form, you can test whether your undesirable situation would occur.

This is "air code" as a skeleton of what you would do:

Code:
IF DCount( {some conditions} ) > 0 THEN
    DoCmd.OpenForm {some form}
ELSE
    MSGBOX "Don't have anything to work on", vbOKOnly, "Cannot Open Form"
END IF

Of course, you would have to fill in the parts in {}.
 

Users who are viewing this thread

Top Bottom