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!

Trying to use integer variable in SQL query

Status
Not open for further replies.

Minkus

IS-IT--Management
Jul 18, 2003
2
IE
Dim POFROM As Integer

POFROM = Range("H1").Value
Range("B1").Select
With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN=Vantage 5 OID;UID=;PWD=;DB=vantage;OIDP=TCP;OIDS=odbc50;OIDH=vmslinux;DBAM=Direct;DBPR=TCP;DBPA=e:\epic50\vantage\db\;ASC=0" _
), Array(";SR=1;GST=0"))
' .CommandText = Array( _
'"SELECT POHeader.PONum, POHeader.OrderDate, PORel.DueDate" & Chr(13) & "" & Chr(10) & "FROM vantage.POHeader POHeader, vantage.PORel PORel" & Chr(13) & "" & Chr(10) & "WHERE POHeader.PONum = PORel.PONum AND POHeader.Company = PORel.Company AND ((POHeader.PO" _
' , "Num>POFROM
))" & Chr(13) & "" & Chr(10) & "ORDER BY POHeader.PONum")
.CommandText = Array( _
"SELECT POHeader.PONum, POHeader.OrderDate, PORel.DueDate, POHeader.EntryPerson " & Chr(13) & "" & Chr(10) & "FROM vantage.POHeader POHeader, vantage.PORel PORel" & Chr(13) & "" & Chr(10) & "WHERE POHeader.PONum = PORel.PONum AND POHeader.Company = PORel.Company AND ((POHeader.PO" _
, "Num>=0 )) AND (POHeader.OrderDate > PORel.DueDate)" & Chr(13) & "" & Chr(10) & "ORDER BY POHeader.PONum")
.Refresh BackgroundQuery:=False
End With
End Sub

When I have a value in instead of POFROM the query works perfect but when I try to replace with the variable POFROM it doesn't. In visual basic when I highlight or have a watch on POFROM it says it contains the value of cell H1 but the query doesn't execute, Runtime error 1004 General ODBC error. I have some working queries that use date and string variables in the query so I am hoping that it is just a matter of enclosing the variable name with the correct parentheses, examples below for date and string. Any ideas on what needs to be done here, I created the macro but just running a query whilst recording and then just doing some tinkering afterwards.

date is (RcvDtl.ReceiptDate>={d '" & start_date$ & "'})
string is (Vendor.VendorID>='" & from_id$ & "')
 
change:
AND ((POHeader.PO" _
' , "Num>POFROM))" to

AND ((POHeader.PONum>" & POFROM & "))"

Rgds, Geoff
Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
Want the best answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top