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!

How to Search For A Specific Record 1

Status
Not open for further replies.

Jdoggers

Technical User
Feb 20, 2005
43
0
0
US
Hi,
I have a field in an access database that i would like to search through and find a match for some text. I know that the match exists, which i checked before this part. I would like to search through the database and find this specific name in a field called 'setup'. How do i direct vb6 to search for a specific record in an access database. I tried using the myrecordset.findfirst something something method to find the record but that only finds the first record in the list. Also, anyone know where i can get a good vb6 book that is for access databases?
thanks
 
Thanks for your help. When i used this line of code, i inserted my table name in for 'my table' and put the field that im looking for where you said 'myfield'. The string i searched for was where the xxx was. First, i would like to know if there is supposed to be quotes around these items. Second, when i put this code in, it gave an error and said that there should be the word 'case' instead of the '*' for some reason. Any suggestions?
 
Regarding the single quotes it will depend on whether the field is a numeric or a char or even a date.
Numerics don't need it, chars do, dates depends

As for your error please show us your code so we can see if there is something wrong with it.



Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
The code I'm about to write isn't very secure, but it should help you (you should use parameters, but if security isn't an issue this is simpler)...
Code:
' This initializes a connection to your database
Dim con as adodb.connection
Dim com as Command
Dim tab as adodb.recordset
Set con = New ADODB.Connection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\your access file goes here.mdb"
con.Open
Set com = New Command
com.ActiveConnection = con
Set tab = New ADODB.Recordset
tab.CursorLocation = adUseServer

' Here goes what you probably need...
com.commandtext="SELECT myfield FROM table WHERE field='setup'"
tab.open com,,adOpenStatic,adLockBatchOptimistic

' Do whatever you need to do with the data

' Close things...
tab.close

I hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top