Question : Substring not recognized in access

Hi,
I have a query that I am trying to run through vba, and i get an error that says: "Undefined function 'substring' in expression."
This query runs great from query analyzer, but in vba, it does not like it for whatever reason.

 sSQLExt = "SELECT TOP 1 tblSalesExtensions.SalesId, SUBSTRING(tblSalesExtensions.ExtensionId, 8, 3) AS SequenceNumber, s2.ContractEndDate " & _
                "FROM tblSales AS s1 INNER JOIN (tblSalesExtensions " & _
                "INNER JOIN tblSales AS s2 " & _
                "ON s2.SalesID = tblSalesExtensions.ExtensionId) " & _
                "ON tblSalesExtensions.SalesId = s1.SalesID " & _
                "WHERE tblSalesExtensions.SalesId ='" & ContractNum & "'" & _
                "AND s2.IsVoid = 0 " & _
                "ORDER BY tblSalesExtensions.SequenceNumber DESC"

this is what it looks like in my vba code.

I also need to cast the substring that i get to an integer, and I use the following code to do that:
CAST(SUBSTRING(tblSalesExtensions.ExtensionId, 8, 3) AS int) AS SequenceNumber
instead of just doing the substring... but when i do the cast, it gives me an entirely different error message.  "Syntax error (missing operator) in query expression 'CAST(SUBSTRING(tblSalesExtensions.ExtensionId, 8, 3) AS int)'."

But both of the above versions work fine from query analyzer...  Please help, this is very urgent!
Thank you in advance.
-Z

Answer : Substring not recognized in access

Try changing this:
"ORDER BY tblSalesExtensions.SequenceNumber DESC"
to this:
"ORDER BY CINT(MID(tblSalesExtensions.ExtensionId, 8, 3)) DESC"

I think perhaps it is not understanding what sequenceNumber is, thus it is asking for a parameter.

Walt


Random Solutions  
 
programming4us programming4us