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

ADO Find...

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I have a variable that I would like to search (SELECT * FROM etc where etc = variable) by but I'm not sure about how to enter it into the search so that it is not taken as a string...

Also

If the variable is found in the table then i would like to follow up with additional procedures. Will If Find = True Then do this and that Else et etc. I've no idea about howmto go about this.

Thanks,
Marcus
 
Hi dodgyone

There are several ways that you can do your search.
One of the fastest (if not the fastest) is first to check if the search is empty:
-----------------------------
rst.open "SELECT count(*) FROM MyTable WHERE MyVariable=" & TheValue, MyConn
if rst.fields(0)=0 then
'no such record
elseif rst.fields(0)=1 then
'do your stuff
else
'do something else
end if
--------------------------------------------------

or use the .find method:
--------------------------------------------------
'Open the entire table in a recordset.
Rst.Open "Mytable", con, adOpenKeyset, LockOptimistic, adCmdTable
'
if not (rst.eof and rst.bof) then
rst.movefirst
rst.find "MyCol=" & MyValue
if rst.eof then
'such item in table
endif
else
'no recs in table
endif
------------------------------------------------------
You can only use .find to search one column at a time.


Hope this helps.

Sunaj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top