T
tamer05
Hi,
I really need some help, as im getting frustrated trying to get this code to
work on my search form. I took this code from the Issues Template (Access
2003) and tried my best to customize it to work for me.
My programming knowledge is poor, but i managed to understand some of this.
I need help please.
I would highly appretiate if someone would be kind enough to reply me using
my e-mail address, because i couldnt find my first posting.
Thanks in advance.
Tamer
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 AssignedTo
If Not IsNull(Me.AssignedTo) Then
'Create Predicate
strWhere = strWhere & " AND " & "Reports Datasheet.[AssignedTo] = "
& Me.AssignedTo & ""
End If
' If OpenedBy
If Not IsNull(Me.OpenedBy) Then
'Add the predicate
strWhere = strWhere & " AND " & "Reports Datasheet.[OpenedBy] = " &
Me.OpenedBy & ""
End If
' If Status
If Nz(Me.Status) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Reports Datasheet.Status = '" &
Me.Status & "'"
End If
' If Category
If Nz(Me.Category) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Reports Datasheet.Category = '" &
Me.Category & "'"
End If
' If Priority
If Nz(Me.Priority) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Reports Datasheet.Priority = '" &
Me.Priority & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[OpenedDate] >= "
& GetDateFilter(Me.OpenedDateFrom)
ElseIf Nz(Me.OpenedDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Opened Date To
If IsDate(Me.OpenedDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[OpenedDate] <= "
& GetDateFilter(Me.OpenedDateTo)
ElseIf Nz(Me.OpenedDateTo) <> "" Then
strError = cInvalidDateError
End If
' If Due Date From
If IsDate(Me.DueDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[DueDate] >= " &
GetDateFilter(Me.DueDateFrom)
ElseIf Nz(Me.DueDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Due Date To
If IsDate(Me.DueDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[DueDate] <= " &
GetDateFilter(Me.DueDateTo)
ElseIf Nz(Me.DueDateTo) <> "" Then
strError = cInvalidDateError
End If
' If CompanyName
If Nz(Me.CompanyName) <> "" Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "Reports Datasheet.CompanyName Like
'*" & Me.CompanyName & "*'"
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Reports", 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.Browse_All_Reports.Form.Filter = strWhere
Me.Browse_All_Reports.Form.FilterOn = True
End If
End Sub
I really need some help, as im getting frustrated trying to get this code to
work on my search form. I took this code from the Issues Template (Access
2003) and tried my best to customize it to work for me.
My programming knowledge is poor, but i managed to understand some of this.
I need help please.
I would highly appretiate if someone would be kind enough to reply me using
my e-mail address, because i couldnt find my first posting.
Thanks in advance.
Tamer
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 AssignedTo
If Not IsNull(Me.AssignedTo) Then
'Create Predicate
strWhere = strWhere & " AND " & "Reports Datasheet.[AssignedTo] = "
& Me.AssignedTo & ""
End If
' If OpenedBy
If Not IsNull(Me.OpenedBy) Then
'Add the predicate
strWhere = strWhere & " AND " & "Reports Datasheet.[OpenedBy] = " &
Me.OpenedBy & ""
End If
' If Status
If Nz(Me.Status) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Reports Datasheet.Status = '" &
Me.Status & "'"
End If
' If Category
If Nz(Me.Category) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Reports Datasheet.Category = '" &
Me.Category & "'"
End If
' If Priority
If Nz(Me.Priority) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Reports Datasheet.Priority = '" &
Me.Priority & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[OpenedDate] >= "
& GetDateFilter(Me.OpenedDateFrom)
ElseIf Nz(Me.OpenedDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Opened Date To
If IsDate(Me.OpenedDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[OpenedDate] <= "
& GetDateFilter(Me.OpenedDateTo)
ElseIf Nz(Me.OpenedDateTo) <> "" Then
strError = cInvalidDateError
End If
' If Due Date From
If IsDate(Me.DueDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[DueDate] >= " &
GetDateFilter(Me.DueDateFrom)
ElseIf Nz(Me.DueDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Due Date To
If IsDate(Me.DueDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Reports Datasheet.[DueDate] <= " &
GetDateFilter(Me.DueDateTo)
ElseIf Nz(Me.DueDateTo) <> "" Then
strError = cInvalidDateError
End If
' If CompanyName
If Nz(Me.CompanyName) <> "" Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "Reports Datasheet.CompanyName Like
'*" & Me.CompanyName & "*'"
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Reports", 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.Browse_All_Reports.Form.Filter = strWhere
Me.Browse_All_Reports.Form.FilterOn = True
End If
End Sub