if query returns none, do not open form

glrs430

New Member
Joined
Nov 2, 2004
Messages
6
Hi,

I'm new to access and am in need of some help.

I have a search window that will open a form and display searched results. However, I would like it NOT to open the form when there are no results from the query. Instead, I would like to have a pop-up informing user that there is no result based on their search criteria.

Thanks,
Gina
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

nullZero

Active Member
Joined
Nov 14, 2005
Messages
497
This goes in your form that displays your search results...

Code:
Private Sub Form_Load()
    If Me.Recordset.EOF Then
        MsgBox ("No Records Returned")
        DoCmd.Close
    End If
End Sub
 

glrs430

New Member
Joined
Nov 2, 2004
Messages
6
Thanks for getting back to me.

Do I need to declare Me.Recordset? I included the code as is and Access 97 is giving me a compile error, indicating that it doesn't recognize Me.Recordset.

Thanks,
Gina
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,069
Office Version
  1. 365
Platform
  1. Windows
Gina

You might want to take a look at DCount.

You could use this to tell you if there are any records based on your criteria and then open/not open the form accordingly.

How are you currently opening the form and what exactly is your 'search window'?
 

Watch MrExcel Video

Forum statistics

Threads
1,119,002
Messages
5,575,501
Members
412,670
Latest member
Khin Zaw Htwe
Top