Querydef with a string parameter (1 Viewer)

J

jgdavis

Guest
I am having trouble putting a string parameter in the following query. When I have an integer in the parameter the query works fine. Is there a different syntax then:

WHERE (Asset.Cusip = " & CusipX & ")

When CusipX is a string?

Dim Dbs As Database
Dim RstSource As Recordset
Dim QdfSource As QueryDef
Dim SQL As String
Dim CusipX As String
Dim TranIDX As Integer

TranIDX = 114
CusipX = 111111111


SQL = "SELECT Asset.Cusip, Asset.ManagerID, Asset.TranID, Asset.Quantity FROM Asset WHERE (Asset.Cusip = " & CusipX & ") And (Asset.TranID = “ & TranIDX & “) ORDER BY Asset.Quantity;"

Set QdfSource = Dbs.CreateQueryDef("")
QdfSource.SQL = SQL

Set RstSource = QdfSource.OpenRecordset

Any help would be greatly appreciated
 

KDg

Registered User.
Local time
Today, 09:39
Joined
Oct 28, 1999
Messages
181
think I posted my reply on the wrong question - try putting WHERE (Asset.Cusip = " & chr(34) & CusipX & chr(34) & ") -> this will then drop "" around your string variable and keep the SQL happy
Similarly you need surrounding # - chr(35) - for date/time


[This message has been edited by KDg (edited 12-13-1999).]
 
J

John Davis

Guest
= " & "'" & yourstring & "'" also works
 

Users who are viewing this thread

Top Bottom