Message Box when no data

kc5747

Registered User.
Local time
Today, 12:13
Joined
Feb 28, 2002
Messages
11
I have one main form and different queries that populate it depending on which command button is clicked I want a message box to pop up if no records are found. Here is what I have for one of the events:

Private Sub Height_search_Click()
On Error GoTo Err_Height_search_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MainForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!MainForm.RecordSource = "HeightSearch"

Exit_Height_search_Click:
Exit Sub

Err_Height_search_Click:
MsgBox Err.Description
Resume Exit_Height_search_Click

End Sub

Thanks
Kristin
 
Hi Kristin,

You could place some code in the On_Load event of your main form that tests your key field for a null entry e.g:

Private Sub Form_Load()

If IsNull(your KeyFieldNameHere) = True Then
MsgBox "There is no data", vbExclamation
DoCmd.Close
End If
 
The form isn't blank until the command button runs on it so I have to have it under the event: Tried this but it doesn't work:

Private Sub Dam_search_Click()
On Error GoTo Err_Dam_search_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MainForm"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!MainForm.RecordSource = "DamSearch"

If IsNull(Height) = True Then
MsgBox "There is no data", vbExclamation
DoCmd.Close
End If


Exit_Dam_search_Click:
Exit Sub
 
If (RecordsetClone.RecordCount = 0) Then
DoCmd.Close
Beep
MsgBox "There is no data recorded for that period.", vbInformation, "No Data Recorded"
End If
 
I get this error You entered an expression that has an invalid reference to the recordsetClone property.
 

Users who are viewing this thread

Back
Top Bottom