aphelps
Bird Man
- Local time
- Today, 11:33
- Joined
- Aug 2, 2002
- Messages
- 32
Howdy--
I have a DB with many forms, each containing many canned queries (most of which have at least one parameter passed to them), attached to buttons. Many of these queries come up with no records (and should, that's not the problem).
What I'd like to be able to do is, click a button, enter the necessary parameters, and then, if no records fit the parameters, pop up a message box that says "no records" or some such, then closes both the query and the msgbox with the "OK".
I just can't suss out how to make Access see if the query came up empty. Below is one example of how I have tried this. The blue line is where the problem is, I am sure, but I have tried at least a dozen different ways of saying this and can't find the right one (if there is a right one). This includes using stDocName, = 0 instead of isnull, is null after the query name, etc.:
================
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
Dim stDocName As String
stDocName = "qselAllVisitsForAGivenNest"
DoCmd.OpenQuery stDocName, acNormal, acReadOnly
If IsNull(qselAllVisitsForAGivenNest) Then GoTo Empty_query
Exit Sub
Empty_query:
MsgBox "This query returned no records."
DoCmd.Close acQuery, stDocName, acSaveNo
Exit Sub
Exit_Command19_Click:
Exit Sub
Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click
End Sub
==================
I get a variety of error messages which I can detail if necessary. Does anyone know if this is possible (it should be), and what the syntax is to do it?
Thanks for any input!
I have a DB with many forms, each containing many canned queries (most of which have at least one parameter passed to them), attached to buttons. Many of these queries come up with no records (and should, that's not the problem).
What I'd like to be able to do is, click a button, enter the necessary parameters, and then, if no records fit the parameters, pop up a message box that says "no records" or some such, then closes both the query and the msgbox with the "OK".
I just can't suss out how to make Access see if the query came up empty. Below is one example of how I have tried this. The blue line is where the problem is, I am sure, but I have tried at least a dozen different ways of saying this and can't find the right one (if there is a right one). This includes using stDocName, = 0 instead of isnull, is null after the query name, etc.:
================
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
Dim stDocName As String
stDocName = "qselAllVisitsForAGivenNest"
DoCmd.OpenQuery stDocName, acNormal, acReadOnly
If IsNull(qselAllVisitsForAGivenNest) Then GoTo Empty_query
Exit Sub
Empty_query:
MsgBox "This query returned no records."
DoCmd.Close acQuery, stDocName, acSaveNo
Exit Sub
Exit_Command19_Click:
Exit Sub
Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click
End Sub
==================
I get a variety of error messages which I can detail if necessary. Does anyone know if this is possible (it should be), and what the syntax is to do it?
Thanks for any input!