Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL query fails in Access

  • 13-04-2008 12:58pm
    #1
    Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭


    Hey all,

    I have the following SQL query that works fine if I run it in Query Analyser on the MSSQL Server.

    [PHP]SELECT AddressLine1, AddressLine2, AddressLine3, Postcode
    FROM SLCustomerLocation
    INNER JOIN SOPOrderReturn
    ON SOPOrderReturn.CustomerID = SLCustomerLocation.SLCustomerAccountID
    INNER JOIN SOPDespatchReceipt
    ON SOPDespatchReceipt.SOPOrderID = SOPOrderReturn.SOPOrderReturnID
    AND SOPDespatchReceipt.DocumentNo = '<data>';[/PHP]

    I then try to run the same query in MS Access 2007 using this code

    [PHP]Dim str2SQL As String
    str2SQL = "SELECT AddressLine1, AddressLine2, AddressLine3, Postcode"
    str2SQL = str2SQL & " FROM SLCustomerLocation"
    str2SQL = str2SQL & " INNER JOIN SOPOrderReturn"
    str2SQL = str2SQL & " ON SOPOrderReturn.CustomerID = SLCustomerLocation.SLCustomerAccountID"
    str2SQL = str2SQL & " INNER JOIN SOPDespatchReceipt"
    str2SQL = str2SQL & " ON SOPDespatchReceipt.SOPOrderID = SOPOrderReturn.SOPOrderReturnID"
    str2SQL = str2SQL & " AND SOPDespatchReceipt.DocumentNo = "
    str2SQL = str2SQL & "'" & DispatchNumber & "';"

    Dim rs As DAO.Recordset
    Dim db As DAO.Database
    Set db = CurrentDb()
    Set rs = db.OpenRecordset(str2SQL)[/PHP]

    But I get a Syntax Error, Missing operator Error code 3075 when I try to run this.

    Now I have a feeling that I need to use brackets, but I'm not sure how and where they need to be? Anyone got any ideas?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Change your AND to a WHERE in the last section and I think you should be good


  • Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭irlrobins


    Cheers, I'll give that a go later this week. I got a around it using a couple of select sub queries. Not pretty, but it let me continue on with the rest of it for a bit.


Advertisement