First of all let me tell you I am a complete noob when it comes to VBA in access 2007. I have attached a copy of the module for part of a report selector form I created. Everything works until I try to get all records between two dates thru user inputs. I made two unbound blanks in the report selector form named txtstartdate1 and txtenddate1. I want to use the referal date field to get the between dates. So far no luck I know it should be a simple thing. below is the module I am tr'Public Sub inbetween()
' Dim strIntakeBilling As String 'Name of report to open.
' Dim strPurchaseDate As String 'Name of your dateField.
' Dim strWhere As String 'Where condition for OpenReport.
' Const conDateFormat = "\#mm\/dd\/yyyy\#"
' strReport = "rptSales"
' strField = "SaleDate"
' If IsNull(Me.txtStartDate) Then
' If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
' strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
' End If
' Else
' If IsNull(Me.txtEndDate) Then 'Start date, but no End.
' strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
' Else 'Both start and end dates.
' strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
' & " And " & Format(Me.txtEndDate, conDateFormat)
' End If
' End If
Below is the module I want to modify. Any help getting it to work would be greatly appreciated.
Private Sub cmdIntake_Click()
Dim strCountyName As String
Dim strAgencyStatus As String
Dim strReferalSource As String
Dim StrServices As String
Dim StrPOStatus As String
Dim strFilter As String
Dim strStaff As String
' HAVE the report auto open for user
If SysCmd(acSysCmdGetObjectState, acReport, "rptIntakeBilling") <> acObjStateOpen Then
DoCmd.OpenReport "rptIntakeBilling", acViewPreview
End If
' Build criteria string for CountyName field
If IsNull(Me.cboCountyName.Value) Then
strCountyName = "Like '*'"
Else
strCountyName = "='" & Me.cboCountyName.Value & "'"
End If
' Build criteria string for AgencyStatus field
If IsNull(Me.cboAgencyStatus.Value) Then
strAgencyStatus = "Like '*'"
Else
strAgencyStatus = "='" & Me.cboAgencyStatus.Value & "'"
End If
' Build criteria string for ReferalSource field
If IsNull(Me.cboReferalSource.Value) Then
strReferalSource = "Like '*'"
Else
strReferalSource = "='" & Me.cboReferalSource.Value & "'"
End If
' Build criteria string for Services field
If IsNull(Me.cboServices.Value) Then
StrServices = "Like '*'"
Else
StrServices = "='" & Me.cboServices.Value & "'"
End If
' Build criteria string for POStatus field
If IsNull(Me.cboPOStatus.Value) Then
StrPOStatus = "Like '*'"
Else
StrPOStatus = "='" & Me.cboPOStatus.Value & "'"
End If
' Build criteria string for POStaff field
If IsNull(Me.cboStaff.Value) Then
strStaff = "Like '*'"
Else
strStaff = "='" & Me.cboStaff.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[CountyName] " & strCountyName & " AND [AgencyStatus] " & strAgencyStatus & " AND [RefCode] " & strReferalSource & " AND [Service] " & StrServices & " AND [POStatus] " & StrPOStatus & " AND [Staff Initials] " & strStaff
' Apply the filter and switch it on
With Reports![rptIntakeBilling]
.Filter = strFilter
.FilterOn = True
'.txtIntakeReportHeader.Value = _
'"INTAKE REPORT: " & vbCrLf & "Referal Source: " & Me.cboReferalSource.Value _
'& vbCrLf & "County: " & Me.cboCountyName.Value _
'& vbCrLf & "Staff: " & Me.cboStaff.Value
End With
End Sub
' Dim strIntakeBilling As String 'Name of report to open.
' Dim strPurchaseDate As String 'Name of your dateField.
' Dim strWhere As String 'Where condition for OpenReport.
' Const conDateFormat = "\#mm\/dd\/yyyy\#"
' strReport = "rptSales"
' strField = "SaleDate"
' If IsNull(Me.txtStartDate) Then
' If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
' strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
' End If
' Else
' If IsNull(Me.txtEndDate) Then 'Start date, but no End.
' strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
' Else 'Both start and end dates.
' strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
' & " And " & Format(Me.txtEndDate, conDateFormat)
' End If
' End If
Below is the module I want to modify. Any help getting it to work would be greatly appreciated.
Private Sub cmdIntake_Click()
Dim strCountyName As String
Dim strAgencyStatus As String
Dim strReferalSource As String
Dim StrServices As String
Dim StrPOStatus As String
Dim strFilter As String
Dim strStaff As String
' HAVE the report auto open for user
If SysCmd(acSysCmdGetObjectState, acReport, "rptIntakeBilling") <> acObjStateOpen Then
DoCmd.OpenReport "rptIntakeBilling", acViewPreview
End If
' Build criteria string for CountyName field
If IsNull(Me.cboCountyName.Value) Then
strCountyName = "Like '*'"
Else
strCountyName = "='" & Me.cboCountyName.Value & "'"
End If
' Build criteria string for AgencyStatus field
If IsNull(Me.cboAgencyStatus.Value) Then
strAgencyStatus = "Like '*'"
Else
strAgencyStatus = "='" & Me.cboAgencyStatus.Value & "'"
End If
' Build criteria string for ReferalSource field
If IsNull(Me.cboReferalSource.Value) Then
strReferalSource = "Like '*'"
Else
strReferalSource = "='" & Me.cboReferalSource.Value & "'"
End If
' Build criteria string for Services field
If IsNull(Me.cboServices.Value) Then
StrServices = "Like '*'"
Else
StrServices = "='" & Me.cboServices.Value & "'"
End If
' Build criteria string for POStatus field
If IsNull(Me.cboPOStatus.Value) Then
StrPOStatus = "Like '*'"
Else
StrPOStatus = "='" & Me.cboPOStatus.Value & "'"
End If
' Build criteria string for POStaff field
If IsNull(Me.cboStaff.Value) Then
strStaff = "Like '*'"
Else
strStaff = "='" & Me.cboStaff.Value & "'"
End If
' Combine criteria strings into a WHERE clause for the filter
strFilter = "[CountyName] " & strCountyName & " AND [AgencyStatus] " & strAgencyStatus & " AND [RefCode] " & strReferalSource & " AND [Service] " & StrServices & " AND [POStatus] " & StrPOStatus & " AND [Staff Initials] " & strStaff
' Apply the filter and switch it on
With Reports![rptIntakeBilling]
.Filter = strFilter
.FilterOn = True
'.txtIntakeReportHeader.Value = _
'"INTAKE REPORT: " & vbCrLf & "Referal Source: " & Me.cboReferalSource.Value _
'& vbCrLf & "County: " & Me.cboCountyName.Value _
'& vbCrLf & "Staff: " & Me.cboStaff.Value
End With
End Sub