microsoft access question

how do i  create a button on form to search by macro?
Hiroyuki TamuraField EngineerAsked:
Who is Participating?
 
Eric ShermanConnect With a Mentor Accountant/DeveloperCommented:
I think your SQL is not correct ... The Select statement you look like this:

Task = "SELECT * FROM YourTableNameHere WHERE ((YourFieldNameHere Like ""*" & strsearch & "*""))"
Me.RecordSource = Task

ET
0
 
Eric ShermanAccountant/DeveloperCommented:
Use the OnClick Event of your button to run your Macro as shown below.
Capture1
ET
0
 
Hiroyuki TamuraField EngineerAuthor Commented:
thank you.
I need a macro script for searching
Snap1293.jpg
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Hiroyuki TamuraField EngineerAuthor Commented:
I'm getting following error
Private Sub Command5_Click()
Dim strsearch As String
Dim Task As String
'Check if a keyword entered or not
If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then
   MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
   Me.txtSearch.BackColor = vbYellow
   Me.txtSearch.SetFocus
Else
    strsearch = Me.txtSearch.Value
    Task = "SELECT * FROM Copy and Paste WHERE ((Comment Like ""*" & strsearch & "*""))"
   Me.Comment = Task
   Me.txtSearch.BackColor = vbWhite
End If
End Sub

Open in new window

Snap1295.jpg
Snap1296.jpg
0
 
Hiroyuki TamuraField EngineerAuthor Commented:
thank you.
what should i put here?
Snap1297.jpg
0
 
Hiroyuki TamuraField EngineerAuthor Commented:
thank you
0
 
Eric ShermanAccountant/DeveloperCommented:
Post the contents of your string variable Task after it has been populated.

ET
0
 
Eric ShermanAccountant/DeveloperCommented:
Try this for your SELECT statement ...

Task = "SELECT * FROM TableName WHERE FieldName LIKE '*" & strSearch & "*';"


ET
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.