I have a database where multiple entries are made on a daily basis. On my main form, I have a calendar control (unbound) to allow the user to choose a date - defaulted to current date. There is also an option group (4 options) allowing the user to choose the day, week, month or year related to the date chosen on the calendar control - defaulted to week. Finally, a button calls a procedure to generate a report with the following code:
However, using DatePart doesn't seem to do what I thought it would; eg., choosing day now gives a report for that day-number in every month of the year and choosing week gives a report for that week-number in every year.
I can't seem to find a solution to this problem, though I've spent a good three days looking.
Can someone suggest another method or help me correct the code I am using? Any help is most appreciated.
Thanks.
Code:
Private Sub Btn_Report_Click()
On Error GoTo Err_Btn_Report_Click
Dim strDatePart, stDocName, stLinkCriteria, Criteria1, Criteria2 As String
Select Case Me.Time_Choice
Case 1
strDatePart = """d"""
Case 2
strDatePart = """ww"""
Case 3
strDatePart = """m"""
Case 4
strDatePart = """yyyy"""
End Select
stDocName = "PeriodicReport"
Criteria1 = "DatePart(" & strDatePart & ",[Date], 0, 0)"
Criteria2 = "DatePart(" & strDatePart & ", Forms!Switchboard!CalendarDate, 0, 0)"
stLinkCriteria = Criteria2 & " = " & Criteria1
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
Exit_Btn_Report_Click:
Exit Sub
Err_Btn_Report_Click:
MsgBox Err.Description
Resume Exit_Btn_Report_Click
End Sub
However, using DatePart doesn't seem to do what I thought it would; eg., choosing day now gives a report for that day-number in every month of the year and choosing week gives a report for that week-number in every year.
I can't seem to find a solution to this problem, though I've spent a good three days looking.
Can someone suggest another method or help me correct the code I am using? Any help is most appreciated.
Thanks.