By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,039 Members | 1,831 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,039 IT Pros & Developers. It's quick & easy.

Searching a field via code

P: 10
Mr Experts
I am a new user using Access and I want to know how is possible search a field using wildcard (*) to find anything begining with a certain char and display in a form showing a list of records.
By example; the name begin with e and there are many records with names beginning with e but they are similars.
Thanks a lot
Buineugenio
Maputo, Mozambique, Africa
Mar 17 '08 #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,494
When you talk about searching, I presume you are talking about SQL.

The way to find matching records in SQL is in the WHERE clause.
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM [YourTable]
  3. WHERE [YourField] Like 'E*'
Mar 18 '08 #2

P: 10
When you talk about searching, I presume you are talking about SQL.

The way to find matching records in SQL is in the WHERE clause.
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM [YourTable]
  3. WHERE [YourField] Like 'E*'
Thanks, is that I want, only I need to insert in the code, the searching string from a text box in a form.
Thanks a lot
Buineugenio
Maputo, Mozambique, Africa
Mar 24 '08 #3

P: 6
What if you create a query with something like this in Criteria area of the column you want to search:
Like "*" & [Which Customer Name are you looking for?] & "*"

Then, create a command button that opens this query and then set your form data source to the query.
Mar 24 '08 #4

NeoPa
Expert Mod 15k+
P: 31,494
The easiest way is to include a reference to the form control in your query (SQL).
An example might be :
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM [YourTable]
  3. WHERE [YourField] Like Forms!frmYourForm.YourControl & '*'
Mar 25 '08 #5

NeoPa
Expert Mod 15k+
P: 31,494
If creating the SQL in a VBA string you can do it more directly and avoid a control reference in the SQL (Assumes code is run from within the form's module) :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "SELECT * " & _
  4.          "FROM [YourTable] " & _
  5.          "WHERE [YourField] Like '" & Me.YourControl & "*'
Mar 25 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.