I am trying to automate a report I do and I have the desired end report that I need. I am just trying to make sure that the data comes in cleanly. In the form I would like for the end users to put in a beginning and ending date and only the data between those dates appears in the report. The dates are derived from the field name DateCreated so when an end user puts in a beginning and ending date based off the field name DateCreated data from those dates will show in the report. Below is the VBS code I created. If I dont put in dates then I get all of the data which is what I want but if I put in a beginning date 11/1/2010 and the ending date 11/30/2010 nothing shows in the report and I would like to see the data between the two dates. Any reason why?? Any suggestions??
Private Sub Generate_ECM_Report_Click()
On Error GoTo Err_Generate_ECM_Report_Click
Dim stDocName As String
Dim stWhere As String
Dim stDates As String
Dim blnTrim As Boolean
If IsNull(Me.txtBeginning) And Me.txtBeginning = " " Then
If Not IsNull(Me.txtEnding) And Me.txtEnding <> " " Then
stWhere = stWhere & "[DateCreated] <=" & Me.txtEnding & "#"
blnTrim = False
End If
Else
If IsNull(Me.txtEnding) And Me.txtEnding = " " Then
If Not IsNull(Me.txtBeginning) And Me.txtBeginning <> " " Then
stWhere = stWhere & "[DateCreated] >=" & Me.txtBeginning
blnTrim = False
End If
Else
If (Not IsNull(Me.txtBeginning) And Me.txtBeginning <> " ") And (Not IsNull(Me.txtEnding) Or Me.txtEnding <> " ") Then
stWhere = stWhere & "[DateCreated] Between #" & Me.txtBeginning & "# And #" & Me.txtEnding & "#"
blnTrim = False
End If
End If
End If
If blnTrim Then
stWhere = Left(stWhere, Len(stWhere) - 5)
End If
stDocName = "Enterprise Change Management Report"
DoCmd.OpenReport stDocName, acPreview, , stWhere
Exit_Generate_ECM_Report_Click:
Exit Sub
Err_Generate_ECM_Report_Click:
MsgBox Err.Description
Resume Exit_Generate_ECM_Report_Click
End Sub
Private Sub Generate_ECM_Report_Click()
On Error GoTo Err_Generate_ECM_Report_Click
Dim stDocName As String
Dim stWhere As String
Dim stDates As String
Dim blnTrim As Boolean
If IsNull(Me.txtBeginning) And Me.txtBeginning = " " Then
If Not IsNull(Me.txtEnding) And Me.txtEnding <> " " Then
stWhere = stWhere & "[DateCreated] <=" & Me.txtEnding & "#"
blnTrim = False
End If
Else
If IsNull(Me.txtEnding) And Me.txtEnding = " " Then
If Not IsNull(Me.txtBeginning) And Me.txtBeginning <> " " Then
stWhere = stWhere & "[DateCreated] >=" & Me.txtBeginning
blnTrim = False
End If
Else
If (Not IsNull(Me.txtBeginning) And Me.txtBeginning <> " ") And (Not IsNull(Me.txtEnding) Or Me.txtEnding <> " ") Then
stWhere = stWhere & "[DateCreated] Between #" & Me.txtBeginning & "# And #" & Me.txtEnding & "#"
blnTrim = False
End If
End If
End If
If blnTrim Then
stWhere = Left(stWhere, Len(stWhere) - 5)
End If
stDocName = "Enterprise Change Management Report"
DoCmd.OpenReport stDocName, acPreview, , stWhere
Exit_Generate_ECM_Report_Click:
Exit Sub
Err_Generate_ECM_Report_Click:
MsgBox Err.Description
Resume Exit_Generate_ECM_Report_Click
End Sub