Something Wrong In my VBA

vdanelia

Registered User.
Local time
Today, 04:35
Joined
Jan 29, 2011
Messages
215
Hello Dear friends, I use a search code in my form, I modified but it shows me an error:

The original code is which is working (it searches the specified field)

Private Sub cmdSearch_Click()
Dim bkmk As Variant
Dim strField As String

Me.RecordsetClone.MoveFirst
'Find the first record that matches what
'is in the search text box.
Me.RecordsetClone.FindFirst "Brand Like" _
& Chr(34) & Me.txtSearch & "*" & Chr(34)
If Me.RecordsetClone.NoMatch Then
MsgBox "No Match"
Else
bkmk = Me.RecordsetClone.Bookmark
Me.Recordset.Bookmark = bkmk
End If
End Sub


Then I changed it (to search in many fields)

Me.RecordsetClone.FindFirst "Brand Like " _
& Chr(34) & Me.txtSearch & "*" & Chr(34) " _
& "OR Contact Like " _
& Chr(34) & Me.txtSearch & "*" & Chr(34) " _
& "OR Address Like " _
Chr(34) & Me.txtSearch & "*" & Chr(34) "

It says Syntax error:

Help Please

Thank you in Advanced
 
Here you are with it straightened out. You were missing some ampersands and you had some quotes in the wrong place.
Code:
[FONT=Times New Roman][SIZE=3]Me.RecordsetClone.FindFirst "Brand Like “ & Chr(34) & Me.txtSearch & "*" & Chr(34)  & _
" OR Contact Like " & Chr(34) & Me.txtSearch & "*" & Chr(34)   & _
" OR Address Like " & Chr(34) & Me.txtSearch & "*" & Chr(34) [/SIZE][/FONT]
 
Thank You Boblarson

Great
 
Hello Friends I need you professional Help..
this mini search is working perfectly, but i need to extend its functionality (I want that searched data to be filtered by its criteria)..

When I'm searching the record in continuous form is searches, but not filtering the data, then i need to scroll down to see all of the matching records......

Thank you in advanced
 
You could change it to this:

Code:
Dim strWhere As String
 
strWhere = "[FONT=Times New Roman][SIZE=3]Brand Like “ & Chr(34) & Me.txtSearch & "*" & Chr(34)  & _
" OR Contact Like " & Chr(34) & Me.txtSearch & "*" & Chr(34)   & _
" OR Address Like " & Chr(34) & Me.txtSearch & "*" & Chr(34)[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][/SIZE][/FONT] 
[FONT=Times New Roman][SIZE=3]Me.Filter = strWhere[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Me.FilterOn = True[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]
[/SIZE][/FONT]
 
Thank you Boblarson... It works, but if there is not a data it displays error.. I think there must be changed something else:

Private Sub cmdSearch_Click()
Dim bkmk As Variant
Dim strField As String
Dim strWhere As String
Me.RecordsetClone.MoveFirst
strWhere = "Brand Like" & Chr(34) & Me.txtSearch & "*" & Chr(34) & _
"OR Model Like" & Chr(34) & Me.txtSearch & "*" & Chr(34) & _
"OR Product Like" & Chr(34) & Me.txtSearch & "*" & Chr(34) & _
"OR Pnumber Like" & Chr(34) & Me.txtSearch & "*" & Chr(34) & _
"OR Snumber Like" & Chr(34) & Me.txtSearch & "*" & Chr(34) & _
"OR Lend Like" & Chr(34) & Me.txtSearch & "*" & Chr(34)
Me.Filter = strWhere
Me.FilterOn = True
If Me.RecordsetClone.NoMatch Then
MsgBox "No Match"
Else
bkmk = Me.RecordsetClone.Bookmark
Me.Recordset.Bookmark = bkmk
End If
End Sub
 
If you are going to filter then you don't need the other parts. Just have the entire procedure be:

Code:
Dim strWhere As String
 
strWhere = "Brand Like “ & Chr(34) & Me.txtSearch & "*" & Chr(34)  & _
" OR Contact Like " & Chr(34) & Me.txtSearch & "*" & Chr(34)   & _
" OR Address Like " & Chr(34) & Me.txtSearch & "*" & Chr(34)
 
Me.Filter = strWhere
Me.FilterOn = True[FONT=Times New Roman][SIZE=3][/SIZE][/FONT]

Nothing else.
 

Users who are viewing this thread

Back
Top Bottom