NearImpossible
Registered User.
- Local time
- Today, 17:37
- Joined
- Jul 12, 2019
- Messages
- 225
Currently I have some code setup to search a table for a specified string, based on the search criteria of either Serial Number, Asset Tag or Name.
What I would like to do is eliminate the need to select the search criteria and be able to just enter the search string and hit enter to have it search all 3 columns.
Any help is appreciated or if you know of a better way to do this, please let me know.
What I would like to do is eliminate the need to select the search criteria and be able to just enter the search string and hit enter to have it search all 3 columns.
Any help is appreciated or if you know of a better way to do this, please let me know.
Code:
Private Sub SearchEquip_Click()
'Checks to see if Search Criteria was selected
If [Search] = "Select" Then
MsgBox "Please select search criteria", , "Equipment Search"
Exit Sub
End If
'Checks to see if there is a seach string
If Nz(txt) = "" Then
MsgBox "Please enter a search value", , "Equipment Search"
Exit Sub
Else
Dim Rs As DAO.Recordset
' Searches Facility equipment by Serial Number
If [Search] = "Serial Number" Then
If Not IsNull(Me![txt]) Then
Set Rs = Me.RecordsetClone
Rs.FindFirst "[Serial Number] Like '*" & Me.txt & "*'"
Me.[Serial Number].SetFocus
If Not Rs.EOF Then Me.Bookmark = Rs.Bookmark
Let txt = ""
Else
Exit Sub
End If
' Searches Facility equipment by Asset Tag
ElseIf [Search] = "Asset Tag" Then
If Not IsNull(Me![txt]) Then
Set Rs = Me.RecordsetClone
Rs.FindFirst "[Asset Tag] Like '*" & Me.txt & "*'"
Me.[Asset Tag].SetFocus
If Not Rs.EOF Then Me.Bookmark = Rs.Bookmark
Let txt = ""
Else
Exit Sub
End If
' Searches Facility equipment by Device Name
ElseIf [Search] = "Name" Then
If Not IsNull(Me![txt]) Then
Set Rs = Me.RecordsetClone
Rs.FindFirst "[Name] Like '*" & Me.txt & "*'"
Me.[DevName].SetFocus
If Not Rs.EOF Then Me.Bookmark = Rs.Bookmark
Let txt = ""
Else
Exit Sub
End If
End If
' Resets the Search criteria
[Search] = "Select"
End If
End Sub