
Originally Posted by
Robeen
How about using the DLookup function - something like this [not functional code - you'll have to pass the value of your search textbox to the function]:
If IsNull(DLookUp("[AnyField]", "tblAudit", "[ID] = SearchField")) Then
MsgBox "Search item not found."
End If
Thanks Robeen!
I think I am very close in getting there. There is a slight issue though.
I added your codes to it and now two MSGBOX pops up even when the record has been found.
I know somewhere it is not right and I am not very good with Access.
This is how my codes look like now:
Code:
Private Sub cmdSearch_Click()
Dim LSQL As String
Dim LSearchString As String
If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
LSearchString = txtSearchString
'Filter results based on search string
LSQL = "select * from tblAudit"
LSQL = LSQL & " where MRN LIKE '*" & LSearchString & "*'"
Form_FrmAuditTool_sub.RecordSource = LSQL
'Clear search string
txtSearchString = ""
MsgBox "Results have been filtered. Patient MRN containing " & LSearchString & "."
End If
If IsNull(DLookup("[MRN]", "tblAudit", "[MRN] = txtSearchString")) Then
MsgBox "Search item not found."
End If
End Sub