ADO Search Examples

I want to search a recordset from a SQL database for a value that I want to pass as a parameter.  The object.find("Week_Beginning_DT = '04/20/2000') is fine but It does not let me pass a value as a parameter.  It wants a string expression.  What am I doing wrong or is there a better way of doing it.

Thanks,
A1785
a1785Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
wsh2Connect With a Mentor Commented:
You have to put # before and after your date so that SQL knows that is what you are passing.

object.find("Week_Beginning_DT = #04/20/2000#)

To do this dynamically try:

Dim strFind as String

strFind = "Week_Beginning_DT = " _
   & "#" & Format(MyDate, "mm/dd/yyyy") & "#"
object.Find (strFind)
0
 
detiegeCommented:
What do you want to pass as parameter ?

The date ?
0
 
detiegeCommented:
You can do that:

Dim Buff As String

Buff = Param  // Buff = your parameter

object.Find("Week_Beginning_DT = '" & Buff & "'")
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
detiegeCommented:
OOOOPs // = ' = Comment
0
 
detiegeCommented:
0
 
ca_hecklerCommented:
Or you can use T-SQL and build your search as a query:

tTarget = "this is what you looking for"
tQuery = "Select * from MyTable where " _
         "MyField ='" & tTarget & "';"

objRecordset.Open tQuery, objConnection

if (objRecordset.EOF) then
   MsgBox "Not found !"
else

   do while (not objRecordset.EOF)
      'do something here ...
   loop

end if
0
 
a1785Author Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.