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

SQL syntax query in VBA 2

Status
Not open for further replies.

mje397

Programmer
Nov 3, 2004
17
US
Can I declare an SQL statement in a string declared as "strSQL" like this

strSQL= "Store='Store1'AND Product='HardDrive'"

I want to go to that location for which store is Store1 and Product = HardDrive. However its giving some error.
 
What is your actual code? It is a little unclear what you are trying to do. What is the error?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
However its giving some error
Could you by chance post the error message and the relevant code ?
Anyway your WHERE close snippet lack a space:
strSQL= "Store='Store1'[highlight] [/highlight]AND Product='HardDrive'"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This is my code


Dim strSQL As String

strSQL = "Store='Store1' AND Product='HardDrive'"

rst.Find strSQL

However when it comes to rst I am getting the following error

" Arguments are of wrong type, are out of acceptable range or are in conflict with each other"

Both Store and Product are in the same table.

 
So, in ADO the Find method is restricted to one criteria, use the Filter property instead:
rst.Filter = strSQL

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
hi PHV,, It worked,, but I had another statement in my coding.

rst.Find strSQL,1,adSearchForward

when I replaced it with

rst.Filter=strSQL,1,adSearchForward

its giving me an error.. Any idea how to go about !!!!!!!!!
 
Try simply this:
rst.Filter=strSQL

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
What I am trying to do is, Go to a particular record, ( by using rst.Filter=strSQL) do some calculations and then go to the next record.

when I was using FIND instead of FILTER , i was using the code

rst.Find strSQL,1,adSearchForward

How will I traverse from one record to next when I use FILTER?

 
You have to play with the Bookmark property (and the F1 key I'm afraid ;-))
Sometimes Access don't react well on help demands about DAO and/or ADO stuff.
I suggest you to search your local drives for files named ADO*.CHM.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top