D
Dulce Candy
Hello,
I am using ACCESS 2000. I have a search form that is working perfectly. I
can select records by associate name, supervisor, site, and by start and end
dates. I want to add a command button that will open a report using the
filtered records only. Currently the filtered records appear in a datasheet
subform in the form footer of my search form. This is code I am using to
filter on my Search form:
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
' If Associate Name
If Nz(Me.AssociateName) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Exports.associatename = '" &
Me.AssociateName & "'"
End If
' If Supervisor
If Nz(Me.Super) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Exports.Super = '" & Me.Super & "'"
End If
' If Site
If Nz(Me.Site) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Exports.Site = '" & Me.Site & "'"
End If
' If Start Date
If IsDate(Me.StartDate) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Exports.[AuditMonth] >= " &
GetDateFilter(Me.StartDate)
ElseIf Nz(Me.StartDate) <> "" Then
strError = cInvalidDateError
End If
' If End Date
If IsDate(Me.EndDate) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Exports.[AuditMonth] <= " &
GetDateFilter(Me.EndDate)
ElseIf Nz(Me.EndDate) <> "" Then
strError = cInvalidDateError
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Exports", acFormDS, , strWhere, acFormEdit,
acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Exports_subform.Form.Filter = strWhere
Me.Exports_subform.Form.FilterOn = True
End If
End Sub
Function GetDateFilter(dtDate As Date) As String
' Date filters must be in MM/DD/YYYY format
GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY hh:mm:ss AM/PM") & "#"
End Function
Your help is appreciated!
I am using ACCESS 2000. I have a search form that is working perfectly. I
can select records by associate name, supervisor, site, and by start and end
dates. I want to add a command button that will open a report using the
filtered records only. Currently the filtered records appear in a datasheet
subform in the form footer of my search form. This is code I am using to
filter on my Search form:
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
' If Associate Name
If Nz(Me.AssociateName) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Exports.associatename = '" &
Me.AssociateName & "'"
End If
' If Supervisor
If Nz(Me.Super) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Exports.Super = '" & Me.Super & "'"
End If
' If Site
If Nz(Me.Site) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Exports.Site = '" & Me.Site & "'"
End If
' If Start Date
If IsDate(Me.StartDate) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Exports.[AuditMonth] >= " &
GetDateFilter(Me.StartDate)
ElseIf Nz(Me.StartDate) <> "" Then
strError = cInvalidDateError
End If
' If End Date
If IsDate(Me.EndDate) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Exports.[AuditMonth] <= " &
GetDateFilter(Me.EndDate)
ElseIf Nz(Me.EndDate) <> "" Then
strError = cInvalidDateError
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Exports", acFormDS, , strWhere, acFormEdit,
acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Exports_subform.Form.Filter = strWhere
Me.Exports_subform.Form.FilterOn = True
End If
End Sub
Function GetDateFilter(dtDate As Date) As String
' Date filters must be in MM/DD/YYYY format
GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY hh:mm:ss AM/PM") & "#"
End Function
Your help is appreciated!