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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help searching an access database

Status
Not open for further replies.

Fion

Vendor
Sep 25, 2003
50
US
Hi, I am tring to figure out how to search an Access database. Here is my current code...

Dim rstInfo As Recordset
Dim db As Database
Dim item
Set db = OpenDatabase(App.Path & dbpath)
Set rstInfo = db.OpenRecordset("Info", dbOpenDynaset)
rstInfo.FindFirst "Name=" & Criti.Text
With rstInfo
.Edit
Set item = Mlist.ListItems.Add(, , !ID)
If Len(!Name) <> 0 Then item.SubItems(1) = !Name
If Len(!Location) <> 0 Then item.SubItems(2) = !location
If Len(!group) <> 0 Then item.SubItems(3) = !group
If Len(!Notes) <> 0 Then item.SubItems(4) = !Notes
End With
End Sub

Now if I use ID (the key field) then it works fine, but I can't get it it search the Name field for a specific name. Is that possible? Maybe I programmed something wrong?
 

Perhaps you may want to ...

[tt]
SQLWueryString = "Select * From Info Where [Name] = '" & Criti.Text & "'" 'for an exact match if you want to use wildcards use the Like operator instead of =
[/tt]

instead of opening the entire table/query and searching through the resulting recordset.

If you use the query method then you will need to test to see if you found one record, more than one record, or none.

I also notice that you are not checking to see if there was a match in your find.

Also the word "Name" is a reserved word in access. You may want (if you want to try your current code without changing too much) to try your code with brackets around the word "Name" like so [Name], or you can change it in the db to say FName or MName or LName or WName (Whole Name).

BTW have you read FAQ222-2244 yet?

Good Luck

 
Yes actually, I did. Thanks for your help! I ended up being able to make my code work perfectly, I didn't have to use the sql commands... But I do really appreaciate your reply and your tring to help.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top