I want to know how to do search for records in tables using Visual basic in MS access.


Example

let say we have a table name "abc" in the following format with the saved records like that
Company code and About company are two text fields in tables.
Companycode ................... About company
123 ......................................xyzzza
145 ......................................xxz
147 .......................................a
where dots '.' just for separation and its nothing
i want to search "x" in "About company", "x" found in two company codes "123" and "145"
when i click on "search" button for finding x it should return me
123 and 145.


Please guide me about this problem,i am new in access vb.

So basically you want to search for companies which start with 'x' ? In that case you case use a pattern-matching SQL.

For the above example, you can use

Dim rs as recordset
set rs = db.Openrecordset("SELECT CompanyCode FROM abc WHERE AboutCompany LIKE 'x*'")

Now the recordset will contain the companycodes of all companies starting with 'x'. Do note the '*' after x. Access uses that symbol for pattern matching.

So basically you want to search for companies which start with 'x' ? In that case you case use a pattern-matching SQL.

For the above example, you can use

Dim rs as recordset
set rs = db.Openrecordset("SELECT CompanyCode FROM abc WHERE AboutCompany LIKE 'x*'")

Now the recordset will contain the companycodes of all companies starting with 'x'. Do note the '*' after x. Access uses that symbol for pattern matching.

Thanks for ur reply,basically i want to search for companies which contains "x" character .Always start with "x" is not compulsary.
for example.it may like this (modifying above example)
Companycode ................... About company
123 ......................................ayxzzza

so "x" character contain in that string("ayxzzza").

Maybe something like this:

Dim rs as recordset
set rs = db.Openrecordset("SELECT CompanyCode FROM abc WHERE AboutCompany LIKE '*x*'")

Here * stands for zero or more characters. So this query will pull out records like xaz, taz, z etc.

This article has been dead for over six months. Start a new discussion instead.