Creating a report receiving input on range
Hi,
Trying to figure out where I went wrong with this chunk of code What I'm basically trying to do is, have a user enter two dates into text boxes(with the appropriate inputmask) To define a range to display on a report. So I've been poking at this for the last few hours, the date is being extracted fine, and inserted into the variables fine according to the Watches I've placed on the variables. What I think it is is something in the syntax in the DoCmd.OpenReport, But I'm not sure, all I know is that it was inserting the date fine into the WHERE part of the DoCmd.OpenReport line. I left some rem statements in there, as I tried it a few different ways just for fear. Forewarning, this entire current project is my first attempt at Access/VBA programming, so it may not look pretty. Thanks in advance for any help.
Private Sub ViewPayrollByEmp_Click()
On Error GoTo Err_ViewPayrollByEmp_Click
Dim dtDateFrom As Date
Dim dtDateTo As Date
Dim stWhere As String
Dim stDocName As String
If IsNull(Me.PayrollEmpDateFrom.Value) And IsNull(Me.PayrollEmpDateTo.Value) Then
Exit Sub
Else
dtDateFrom = Me.PayrollEmpDateFrom.Value
dtDateTo = Me.PayrollEmpDateTo.Value
stWhere = Chr$(34) & "[InspectionDate] between " & dtDateFrom & " AND " & dtDateFrom & Chr$(34)
stDocName = "Payroll"
'stWhere = Chr$(34) & "InspectionDate >= " & dtDateFrom & " AND " & "InspectionDate <= " & dtDateTo & Chr$(34)
DoCmd.OpenReport stDocName, acPreview, , stWhere
End If
Exit_ViewPayrollByEmp_Click:
Exit Sub
Err_ViewPayrollByEmp_Click:
MsgBox Err.Description
Resume Exit_ViewPayrollByEmp_Click
End Sub
|