Hi all,
I'm currently trying to fix a database that hasn't been working properly and have come unstuck trying to run a report between 2 dates.
Basically, each report shows a date (DayDate) and belongs to a certain Contract (Contract). I have developed a form with a combo box (cboContract) that offers all possible contract numbers and two boxes where the user inputs StartDate and EndDate.
What I'm trying to do is work out what code I need to ensure that when the user presses the button Run Report (Command19) the report (rptDayworkCheck) will run between the StartDate and End Date. The code I have so far (from miscellaneous sources is as follows)
Code:
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
Dim stDocName, Contract As String
Dim StartDate As Date
Dim EndDate As Date
Dim stLinkCriteria As String
StartDate = Forms!frmContracts1!StartDate
EndDate = Forms!frmContracts1!EndDate
Contract = Forms!frmContracts1!cboContract
stDocName = "rptDayworkCheck"
stLinkCriteria = "[DayDate] Between # " & Format(StartDate, "dd/mm/yyyy") & "# And #" & Format(EndDate, "dd/mm/yyyy") & "#"
DoCmd.OpenReport stDocName, acPreview, stLinkCriteria
Exit_Command19_Click:
Exit Sub
Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click
End Sub
Any help would be greatly (and desperately) appreciated!
I'm currently trying to fix a database that hasn't been working properly and have come unstuck trying to run a report between 2 dates.
Basically, each report shows a date (DayDate) and belongs to a certain Contract (Contract). I have developed a form with a combo box (cboContract) that offers all possible contract numbers and two boxes where the user inputs StartDate and EndDate.
What I'm trying to do is work out what code I need to ensure that when the user presses the button Run Report (Command19) the report (rptDayworkCheck) will run between the StartDate and End Date. The code I have so far (from miscellaneous sources is as follows)
Code:
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
Dim stDocName, Contract As String
Dim StartDate As Date
Dim EndDate As Date
Dim stLinkCriteria As String
StartDate = Forms!frmContracts1!StartDate
EndDate = Forms!frmContracts1!EndDate
Contract = Forms!frmContracts1!cboContract
stDocName = "rptDayworkCheck"
stLinkCriteria = "[DayDate] Between # " & Format(StartDate, "dd/mm/yyyy") & "# And #" & Format(EndDate, "dd/mm/yyyy") & "#"
DoCmd.OpenReport stDocName, acPreview, stLinkCriteria
Exit_Command19_Click:
Exit Sub
Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click
End Sub
Any help would be greatly (and desperately) appreciated!