Good Morning duffyt60 and Welcome!
1) You have not set " TxtSearch " to any value; thus, it is null
2) I'll send you a template in
your Bytes.com>Inbox with some suggestions on how to properly setup the VBA-IDE
The minimum is that you should have both
- Option Explicit
-
Option Compare Database
Set properly
The first one will force you to properly declare your variables
3) It's a guess; however, I suspect that
[Full_Name]
is a text field; thus, you will need to quote the value you are searching for
with the bit of tweaking you now have:
- Private Sub cmdSearch_Click()
-
'
-
Dim myTxtSearch as String
-
myTxtSearch = "[Full_Name]= %1" & me.TxtSearch & "%1"
-
myTxtSearch = Replace(myTxtSearch , "%1", Chr(34))
-
'
-
If IsNull(TxtSearch) = False Then
-
Me.Recordset.FindFirst myTxtSearch
-
Me.TxtSearch = Null
-
If Me.Recordset.NoMatch Then
-
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
-
Me.TxtSearch = Null
-
End If
-
End If
-
-
End Sub
The
replace()
makes inserting the double quote much cleaner otherwise you have silly things such as
""""
- it's a trick I picked up from Neopa
>> BTW: Building the string outside of the function (as I have done in lines 4 and 5) allows you to troubleshoot the string by just inserting a
Debug.print yourStringHere
following the formation and then [<ctrl><G> to open the immediate pane to see the string. A malformed string is one of the more common causes of unexpected results and errors.