Link to home
Start Free TrialLog in
Avatar of Roman F
Roman FFlag for United States of America

asked on

return the message if there are no records

I have a form with many buttons on it. One button has  a simple query:
Select everything from TblMain where the RecDate =10/01/2019
if there are records they should open the results if there are no errors should be message box: there are no records
I need to create a macro
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

In the click event
Dim rst as DAO.Recordset
set rst = CurrentDB.OpenRecrdset("Select *from TblMain where the RecDate =#10/01/2019#")
If rst.RecordCount >0 then
'Now Open the results...its not very clear how you implement this
else
MsgBox "No Records"
End If
If Not rst Is Nothing then set rst = Nothing

Open in new window

Avatar of Roman F

ASKER

i am confused a liitle bit...
Thank you for your response...
when you click on button you run the query...
if there are records you will the results otherwise the message box will inform you...
it should be thru the macro
You need macro ?
Sorry i only do VBA...much much better....is not that hard...just instead of doing "Macro Builder"  you do "Event Builder"
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roman F

ASKER

thank you, Gustav, if I need for example to set my filter instead of the date to something else like the status should be "Pending"...

Dim Filter As String

Filter = "[Status] = "Pending"", is the syntax is ok?
The quotes would be slightly different:

Filter = "[Status] = 'Pending'"

Open in new window

Avatar of Roman F

ASKER

instead of using the table, may i use the query?

If DCount("*", qrySelection, Filter) = 0 Then
Perhaps. We don't have your query, but try.
Avatar of Roman F

ASKER

thank you
You are welcome!