Lavenderchan
Technical User
Hi I used the issues database templete for the model of my current data base. I am trying to replacate the search button to have my unbound form I'm using to search a sub form but I can not get it to work properly. When I try to search an error 2448 can't assign to object. That last to lines in my code become yellow. I have read and done everything possible. I'm not sure what else to do. here is my code: Option Compare Database
Option Explicit
Private Sub Clear_Click()
DoCmd.Close
DoCmd.OpenForm "Search Tasks"
End Sub
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 Property Name
If Not IsNull(Me.Property_Name) Then
'Create Predicate
strWhere = strWhere & " AND " & "Tracking Log.[Property Name] = " & Me.Property_Name & ""
End If
' If Assigned To
If Not IsNull(Me.Assigned_To) Then
'Create Predicate
strWhere = strWhere & " AND " & "Tracking Log.[Assigned To] = " & Me.Assigned_To & ""
End If
' If Opened By
If Not IsNull(Me.Opened_By) Then
'Add the predicate
strWhere = strWhere & " AND " & "Tracking Log.[Opened By] = " & Me.Opened_By & ""
End If
' If Status
If Nz(Me.Status) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Tracking Log.Status = '" & Me.Status & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Tracking Log.[Opened Date] >= " & 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 " & "Tracking Log.[Opened Date] <= " & 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 " & "Tracking Log.[Due Date] >= " & 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 " & "Tracking Log.[Due Date] <= " & GetDateFilter(Me.DueDateTo)
ElseIf Nz(Me.DueDateTo) <> "" Then
strError = cInvalidDateError
End If
'If Task
If Nz(Me.Task) <> "" Then
'Add it to the predicate - exact
strWhere = strWhere & "AND" & "TrackingLog.Task ='" & Me.Task & ""
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Search Tasks", acFormsDS,, 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_Tasks.Form.Filter = strWhere
Me.Browse_All_Tasks.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") & "#"
End Function
Please any help would be sincerely appreicated. I really fustracted right now. I did start another thread with this problam in the wrong form. I not sure how to delete it but here is the form number thread181-1512143.
Thanks,
Keri
Option Explicit
Private Sub Clear_Click()
DoCmd.Close
DoCmd.OpenForm "Search Tasks"
End Sub
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 Property Name
If Not IsNull(Me.Property_Name) Then
'Create Predicate
strWhere = strWhere & " AND " & "Tracking Log.[Property Name] = " & Me.Property_Name & ""
End If
' If Assigned To
If Not IsNull(Me.Assigned_To) Then
'Create Predicate
strWhere = strWhere & " AND " & "Tracking Log.[Assigned To] = " & Me.Assigned_To & ""
End If
' If Opened By
If Not IsNull(Me.Opened_By) Then
'Add the predicate
strWhere = strWhere & " AND " & "Tracking Log.[Opened By] = " & Me.Opened_By & ""
End If
' If Status
If Nz(Me.Status) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "Tracking Log.Status = '" & Me.Status & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "Tracking Log.[Opened Date] >= " & 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 " & "Tracking Log.[Opened Date] <= " & 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 " & "Tracking Log.[Due Date] >= " & 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 " & "Tracking Log.[Due Date] <= " & GetDateFilter(Me.DueDateTo)
ElseIf Nz(Me.DueDateTo) <> "" Then
strError = cInvalidDateError
End If
'If Task
If Nz(Me.Task) <> "" Then
'Add it to the predicate - exact
strWhere = strWhere & "AND" & "TrackingLog.Task ='" & Me.Task & ""
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Search Tasks", acFormsDS,, 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_Tasks.Form.Filter = strWhere
Me.Browse_All_Tasks.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") & "#"
End Function
Please any help would be sincerely appreicated. I really fustracted right now. I did start another thread with this problam in the wrong form. I not sure how to delete it but here is the form number thread181-1512143.
Thanks,
Keri