Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

serachin an access table using VB 6.0

Status
Not open for further replies.

compukid

Programmer
Mar 31, 2002
1
0
0
US
hi,
I have a access database...and i have made a front end using VB so that i can add and delete stuff from the table in the .mdb file..
Now i want to add a "find" feature so that i can search for a particular record in the table.Say the table has Name and ID. I want to search using Name . I type the Name in the text box and hit find and all records with that Name shud be displayed with the Id's.
I cant figure out how to do this. Please be very detailed in your reply as this is my first time in VB and i harldy know much . I am learning. I need someone to tell me once how to do a search and then i can go on from there. Thanx a lot for your time.
byeeeeeee ;-)
 
HAI,
if u have table having fields custid,custname and other details if put a combobox to ask user to select search criteria by custid or name or street anything.
and write the query ..
Select custname from customer where custname like '%txtsearch.text%'

This will return all names having the search text .
Regrs,
Sweth
 
Ok. If You're using DAO as your reference then here's the code.

1. Go to Project Reference and then Select Microsoft DAO 3.51
2. Open the Database and the Recordset......
If you are searching use dbOpenDynaset if adding records use dbOpenTable...

Assuming that you have a TextBox where you type the item to search...

Private db as Database
Private rs as Recordset

Private Sub Command1_Click()
Set db = OpenDatabase("c:\Project\....\Project.mdb")
Set rs = db.OpenRecordset("TableName",dbOpenDynaset)

With rs
.FindFirst "FieldName='" & TextBox & "'"
If Not .NoMatch then
'Put your code here
'If you want to display the item being
search then....

Text1.Text = !Field1
Text1.Text = !Field2
Text1.Text = !Field3
................
................
Else
MsgBox "Item Not Found", vbExclamation, "Search"
Endif

End With
rs.Close
Set rs = Nothing [smile]



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top