Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

microsoft access question

Posted on 2016-10-07
8
Medium Priority
?
67 Views
Last Modified: 2016-10-07
how do i  create a button on form to search by macro?
0
Comment
Question by:Hiroyuki Tamura
  • 4
  • 4
8 Comments
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41833806
Use the OnClick Event of your button to run your Macro as shown below.
Capture1
ET
0
 

Author Comment

by:Hiroyuki Tamura
ID: 41833842
thank you.
I need a macro script for searching
Snap1293.jpg
0
 

Author Comment

by:Hiroyuki Tamura
ID: 41833985
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 19

Accepted Solution

by:
Eric Sherman earned 2000 total points
ID: 41834025
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
 

Author Comment

by:Hiroyuki Tamura
ID: 41834074
thank you.
what should i put here?
Snap1297.jpg
0
 

Author Closing Comment

by:Hiroyuki Tamura
ID: 41834100
thank you
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41834143
Post the contents of your string variable Task after it has been populated.

ET
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41834190
Try this for your SELECT statement ...

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


ET
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question