Hey gang!
Below code allows me to search my database though all fields included on the form. Works great. Small issue, when I fetch partial phrases, if they contain an apostrophy, say, "Ferris Bueller's Day Off", Access does not understand it an gives me either ther 3075 error, or the other.
What are your thoughts on that?
Any information you have is appreciated.
My apologies re; Code tags, too long of a procedure, couldn't add CODE=VB.
Have a great week-end, thanks!
Dököll
Below code allows me to search my database though all fields included on the form. Works great. Small issue, when I fetch partial phrases, if they contain an apostrophy, say, "Ferris Bueller's Day Off", Access does not understand it an gives me either ther 3075 error, or the other.
What are your thoughts on that?
Option Compare Database
Option Explicit
'Refresh form screen for new data entry
Private Sub ResetMeScreen_C lick()
DoCmd.Close 'the form must close, then reopened
DoCmd.OpenForm "DataCentralRep ort"
End Sub
'Search button
Private Sub SearchMeData_Cl ick()
Const cInvalidDateErr or As String = "Please enter date in proper format to continue..."
'Date format catcher. This keeps the data clean and standard
Dim strWhere As String 'Dimensioned to be called through command
Dim strError As String 'Dimensioned to be called below
strWhere = "1=1"
If Not IsNull(Me.AsTo) Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[AsTo] = '" & Me.AssignedTo & "'"
End If
If Not IsNull(Me.OpToT hen 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[OpTo= '" & Me.OpenedBy & "'"
End If
If Nz(Me.Status) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Status] = '" & Me.Status & "'"
End If
If Nz(Me.Category) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Category] = '" & Me.Category & "'"
End If
If Nz(Me.CoName) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[CoName] = '" & Me.CoName & "'"
End If
If Nz(Me.Code) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Code] = '" & Me.Code & "'"
End If
If Nz(Me.Priority) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Priority] = '" & Me.Priority & "'"
End If
If IsDate(Me.Begin ningDate) Then 'Loads data searched if dates available
strWhere = strWhere & " AND " & "DataCentra l.[TodayDate] >= " & GetDateFilter(M e.BeginningDate )
ElseIf Nz(Me.Beginning Date) <> "" Then
strError = cInvalidDateErr or
End If
If IsDate(Me.Endin gDate) Then 'Loads data searched if dates available
strWhere = strWhere & " AND " & "DataCentra l.[TodayDate] <= " & GetDateFilter(M e.EndingDate)
ElseIf Nz(Me.EndingDat e) <> "" Then
strError = cInvalidDateErr or
End If
If Nz(Me.ContactPe rson) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentral.Co ntactPerson Like '*" & Me.ContactPerso n & "*'"
End If
If Nz(Me.Items) <> "" Then 'Loads data searched if available
'Like helps get part of the text then searched
strWhere = strWhere & " AND " & "DataCentral.It ems Like '*" & Me.IssuesItems & "*'"
End If
'If Nz(Me.LegacyDat e) <> "" Then 'Loads data searched if dates available
'strWhere = strWhere & " AND " & "DataCentral.Le gacyDate Like '*" & Me.LegacyDate & "*'"
'End If
If Nz(Me.ID) <> "" Then 'Loads data searched if dates available
strWhere = strWhere & " AND " & "DataCentra l.ID Like '*" & Me.ID & "*'"
End If
If strError <> "" Then 'Pop up catch when search is cancelled
MsgBox "You decided to cancel your search..." 'strError
Else
If Not Me.FormFooter.V isible Then 'results loads in additional form in footer
Me.FormFooter.V isible = True
DoCmd.MoveSize Height:=Me.Wind owHeight + Me.FormFooter.H eight
End If
Me.DataCentralR esultsForm.Form .Filter = strWhere
Me.DataCentralR esultsForm.Form .FilterOn = True
End If
End Sub
Function GetDateFilter(d tDate As Date) As String
GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY") & "#"
End Function
Option Explicit
'Refresh form screen for new data entry
Private Sub ResetMeScreen_C lick()
DoCmd.Close 'the form must close, then reopened
DoCmd.OpenForm "DataCentralRep ort"
End Sub
'Search button
Private Sub SearchMeData_Cl ick()
Const cInvalidDateErr or As String = "Please enter date in proper format to continue..."
'Date format catcher. This keeps the data clean and standard
Dim strWhere As String 'Dimensioned to be called through command
Dim strError As String 'Dimensioned to be called below
strWhere = "1=1"
If Not IsNull(Me.AsTo) Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[AsTo] = '" & Me.AssignedTo & "'"
End If
If Not IsNull(Me.OpToT hen 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[OpTo= '" & Me.OpenedBy & "'"
End If
If Nz(Me.Status) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Status] = '" & Me.Status & "'"
End If
If Nz(Me.Category) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Category] = '" & Me.Category & "'"
End If
If Nz(Me.CoName) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[CoName] = '" & Me.CoName & "'"
End If
If Nz(Me.Code) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Code] = '" & Me.Code & "'"
End If
If Nz(Me.Priority) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentra l.[Priority] = '" & Me.Priority & "'"
End If
If IsDate(Me.Begin ningDate) Then 'Loads data searched if dates available
strWhere = strWhere & " AND " & "DataCentra l.[TodayDate] >= " & GetDateFilter(M e.BeginningDate )
ElseIf Nz(Me.Beginning Date) <> "" Then
strError = cInvalidDateErr or
End If
If IsDate(Me.Endin gDate) Then 'Loads data searched if dates available
strWhere = strWhere & " AND " & "DataCentra l.[TodayDate] <= " & GetDateFilter(M e.EndingDate)
ElseIf Nz(Me.EndingDat e) <> "" Then
strError = cInvalidDateErr or
End If
If Nz(Me.ContactPe rson) <> "" Then 'Loads data searched if available
strWhere = strWhere & " AND " & "DataCentral.Co ntactPerson Like '*" & Me.ContactPerso n & "*'"
End If
If Nz(Me.Items) <> "" Then 'Loads data searched if available
'Like helps get part of the text then searched
strWhere = strWhere & " AND " & "DataCentral.It ems Like '*" & Me.IssuesItems & "*'"
End If
'If Nz(Me.LegacyDat e) <> "" Then 'Loads data searched if dates available
'strWhere = strWhere & " AND " & "DataCentral.Le gacyDate Like '*" & Me.LegacyDate & "*'"
'End If
If Nz(Me.ID) <> "" Then 'Loads data searched if dates available
strWhere = strWhere & " AND " & "DataCentra l.ID Like '*" & Me.ID & "*'"
End If
If strError <> "" Then 'Pop up catch when search is cancelled
MsgBox "You decided to cancel your search..." 'strError
Else
If Not Me.FormFooter.V isible Then 'results loads in additional form in footer
Me.FormFooter.V isible = True
DoCmd.MoveSize Height:=Me.Wind owHeight + Me.FormFooter.H eight
End If
Me.DataCentralR esultsForm.Form .Filter = strWhere
Me.DataCentralR esultsForm.Form .FilterOn = True
End If
End Sub
Function GetDateFilter(d tDate As Date) As String
GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY") & "#"
End Function
My apologies re; Code tags, too long of a procedure, couldn't add CODE=VB.
Have a great week-end, thanks!
Dököll
Comment