T
Tony Williams
I have a query that has certain criteria. The results are displayed in a
form. If there are no records I want a message box to appear saying so
rather than the form. I have done this with a query that runs a report
using this code behind the OnNoData property
Private Sub cmdViewReport_Click()
On Error GoTo HandleErr
Me.Visible = False
Dim stDocName As String
stDocName = "rptDocbyDate"
If IsNull(Me.StartDatetxt) Then MsgBox "Please enter Start Date",
vbExclamation, "Enter Start Date"
Me.StartDatetxt.SetFocus
Cancel = True
If IsNull(Me.EndDatetxt) Then MsgBox "Please enter End Date",
vbExclamation, "Enter End Date"
Me.EndDatetxt.SetFocus
Cancel = True
If Not IsNull(StartDatetxt) And Not IsNull(EndDatetxt) And Not
IsNull(finddocnametxt) Then
DoCmd.Minimize
DoCmd.OpenReport stDocName, acPreview
End If
Exit_cmbViewReport_Click:
Exit Sub
HandleErr:
Select Case Err.Number
Case 2501
'The OpenReport action was cancelled.
'There no rows. So do nothing.
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume Exit_cmbViewReport_Click
End Sub
How can I use this code to get the same effect for the query that creates a
form?
TIA
Tony Williams
PS I'm a relative newbie so would appreciate answers not too technical
please
form. If there are no records I want a message box to appear saying so
rather than the form. I have done this with a query that runs a report
using this code behind the OnNoData property
Private Sub cmdViewReport_Click()
On Error GoTo HandleErr
Me.Visible = False
Dim stDocName As String
stDocName = "rptDocbyDate"
If IsNull(Me.StartDatetxt) Then MsgBox "Please enter Start Date",
vbExclamation, "Enter Start Date"
Me.StartDatetxt.SetFocus
Cancel = True
If IsNull(Me.EndDatetxt) Then MsgBox "Please enter End Date",
vbExclamation, "Enter End Date"
Me.EndDatetxt.SetFocus
Cancel = True
If Not IsNull(StartDatetxt) And Not IsNull(EndDatetxt) And Not
IsNull(finddocnametxt) Then
DoCmd.Minimize
DoCmd.OpenReport stDocName, acPreview
End If
Exit_cmbViewReport_Click:
Exit Sub
HandleErr:
Select Case Err.Number
Case 2501
'The OpenReport action was cancelled.
'There no rows. So do nothing.
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume Exit_cmbViewReport_Click
End Sub
How can I use this code to get the same effect for the query that creates a
form?
TIA
Tony Williams
PS I'm a relative newbie so would appreciate answers not too technical
please