G
gorsoft
I am using a form opened in dialog mode to enter start and end dates
as parameters for a report. The form is opened when I call the report.
Once the date parameters are entered, I make the diaolog form
invisible and allow the rest of the report code to run.
The form is specified in a constantrivate Const ScheduleCriteriaForm
As String = "frmChooseReportDate2"
Then in the open event of the report:
DoCmd.OpenForm ScheduleCriteriaForm, acNormal, , , , acDialog
' See if criteria form is still open:
On Error Resume Next
Set objFRM = Forms(ScheduleCriteriaForm)
' Stop report from opening if criteria form is closed:
If Err.Number <> 0 Then
Cancel = True
End If
Then I build the code for the data source of the report (strSQL) and
the criteria (strWhere) and the rest of the report code is as follows:
'Initialize SELECT statement.
MyRecordsource = strSql
' Set RecordSource property of Details Report.
Reports!rptInvoiceSchedule.RecordSource = MyRecordsource
In the close event of the report, the invisible dialog box itself is
closed.
This all works fine but I want to insert error trapping code where the
user forgets to enter either or both of the date parameters (txtFrom
and txtTo) in the dialog box.
I have tried the following:
Select Case Forms!frmChooseReportDate2!txtFrom
Case Is = Null
strMsg = "You must enter a date in both fields."
If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
Case Is = Not Null
Select Case Me!txtTo
Case Is = Null
strMsg = "You must enter a date in both fields."
If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
Case Is = Not Null
'Do nothing
End Select
End select
But where should I place this code? I tried putting it in the View
Report button on the dialog form but this just hangs.
Any ideas appreciated.
Gina
as parameters for a report. The form is opened when I call the report.
Once the date parameters are entered, I make the diaolog form
invisible and allow the rest of the report code to run.
The form is specified in a constantrivate Const ScheduleCriteriaForm
As String = "frmChooseReportDate2"
Then in the open event of the report:
DoCmd.OpenForm ScheduleCriteriaForm, acNormal, , , , acDialog
' See if criteria form is still open:
On Error Resume Next
Set objFRM = Forms(ScheduleCriteriaForm)
' Stop report from opening if criteria form is closed:
If Err.Number <> 0 Then
Cancel = True
End If
Then I build the code for the data source of the report (strSQL) and
the criteria (strWhere) and the rest of the report code is as follows:
'Initialize SELECT statement.
MyRecordsource = strSql
' Set RecordSource property of Details Report.
Reports!rptInvoiceSchedule.RecordSource = MyRecordsource
In the close event of the report, the invisible dialog box itself is
closed.
This all works fine but I want to insert error trapping code where the
user forgets to enter either or both of the date parameters (txtFrom
and txtTo) in the dialog box.
I have tried the following:
Select Case Forms!frmChooseReportDate2!txtFrom
Case Is = Null
strMsg = "You must enter a date in both fields."
If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
Case Is = Not Null
Select Case Me!txtTo
Case Is = Null
strMsg = "You must enter a date in both fields."
If MsgBox(strMsg, vbOKCancel) = vbCancel Then Exit Sub
Case Is = Not Null
'Do nothing
End Select
End select
But where should I place this code? I tried putting it in the View
Report button on the dialog form but this just hangs.
Any ideas appreciated.
Gina