Need help to have this code in a LOOP.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I need to say if there is no such date, then to be able to go and retry until it will find a matched DATE.

Thanks

strRepDate = InputBox("Please enter the Report's Date you wish to view", "View BPL Report by date"
If IsDate(strRepDate) = False The
MsgBox "Please enter a date as 1/1/04", vbOKOnl
Els
If strRepDate = CStr(strRepDate) Then
strDocName = "rptMasterBPLReport
strWhere = "[IncidentDate] = #" & strRepDate & "#
DoCmd.OpenReport strDocName, acViewPreview, , strWher
End If
 
If you mean to re-pop up the InputBox if user entered invalid date, try
this:

Dim bolValid As Boolean
Dim bolCanceled As Boolean
Dim strInput As String

Do
bolValid=True
strInput=InputBox("Please enter a date:","Input Date")
If strInput="" Then
bolCanceled=True
Exit Do
End If
If Not IsDate(strInput) Then bolValid=False
Loop Until bolValid

If bolCancel Then Exit Sub

'Open your report here
strDocName = "rptMasterBPLReport"
strWhere = "[IncidentDate] = #" & strRepDate & "#"
DoCmd.OpenReport strDocName, acViewPreview, , strWhere



uma1919 said:
Hi,
I need to say if there is no such date, then to be able to go and retry
until it will find a matched DATE.
Thanks,

strRepDate = InputBox("Please enter the Report's Date you wish to view", "View BPL Report by date")
If IsDate(strRepDate) = False Then
MsgBox "Please enter a date as 1/1/04", vbOKOnly
Else
If strRepDate = CStr(strRepDate) Then
strDocName = "rptMasterBPLReport"
strWhere = "[IncidentDate] = #" & strRepDate & "#"
DoCmd.OpenReport strDocName, acViewPreview, , strWhere
End If
 
Several ways to do this
The best way would be to make a form for the report
where you have a combobox shoving distinct dates from your source table
(even fancier - one to select year and / or month & then displaying the
relevant dates)
and then opening the report based on that

you could also use the report_nodata event to set a global value indicating
wether the criteria was met (clear it afterwards!)

or run a query against the reports recordsource based on the criteria to
determine wether to nag for a date again...

HTH

Pieter

uma1919 said:
Hi,
I need to say if there is no such date, then to be able to go and retry
until it will find a matched DATE.
Thanks,

strRepDate = InputBox("Please enter the Report's Date you wish to view", "View BPL Report by date")
If IsDate(strRepDate) = False Then
MsgBox "Please enter a date as 1/1/04", vbOKOnly
Else
If strRepDate = CStr(strRepDate) Then
strDocName = "rptMasterBPLReport"
strWhere = "[IncidentDate] = #" & strRepDate & "#"
DoCmd.OpenReport strDocName, acViewPreview, , strWhere
End If
 
Back
Top