Consulting

Results 1 to 5 of 5

Thread: Solved: SQL error

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Solved: SQL error

    I am having trouble ( as usual ) with the following

    I am using excel to extract records from an access database and have got stuck with the following

    [vba]Src = "SELECT TblAddress.AddressType, _
    TblAddress.LeadNumber, _
    TblAddress.Title, _
    TblAddress.LastName, _
    TblAddress.AddressLine1, _
    TblAddress.PostCodeIn, _
    TblAddress.PostCodeOut FROM TblAddress _
    WHERE (((TblAddress.AddressType) = "I")) _
    WITH OWNERACCESS OPTION;"[/vba]

    I am getting a sytax error
    I don't think I've got the line wrapping right and when I put it all on one line, (((TblAddress.AddressType) = "I")) causes a problem aswell

    Any help greatly appreciated.

  2. #2
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Try:
    Src = "SELECT TblAddress.AddressType, " & _
    "TblAddress.LeadNumber, " & _
    "TblAddress.Title, " & _
    "TblAddress.LastName, " & _
    "TblAddress.AddressLine1, " & _
    "TblAddress.PostCodeIn, " & _
    "TblAddress.PostCodeOut FROM TblAddress " & _
    "WHERE (((TblAddress.AddressType) = 'I')) " & _
    "With OWNERACCESS OPTION;"
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Thanks Rory

    Thanks Rory
    I tried the single quote rather than double quotes which solved the problem with the variable but I couldn't solve the multi line
    Thanks

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Did you put in the '&' at the end of each line too? Works fine for me.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    Quote Originally Posted by rory
    Did you put in the '&' at the end of each line too? Works fine for me.
    Sorry
    Yes it does work
    What I meant was, yes, you gave me the solution for the multiline which I couldn't work out, but I had worked out the single quote marks around the variable before you replied

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •