dcsimg
Results 1 to 5 of 5

Thread: Run-time error 3075 - Syntax error in string in query expression VB6/MS-access

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    3

    Run-time error 3075 - Syntax error in string in query expression VB6/MS-access

    Hi,
    I have an access db that I am trying to query from a vb6 program. I've the following code:
    Dim sSQLQuery As String
    sSQLQuery = "SELECT * FROM TblData WHERE ID = " & Chr(39) & ID & Chr(39)

    ID here is equal to 1234567890

    MsgBox sSQLQuery
    the msgbox says: SELECT * FROM TblData WHERE ID = '1234567890 Note that the quotation is missing at the end

    Set rs = db.OpenRecordset(sSQLQuery, dbOpenDynaset)
    Here I get the error:
    Run-time error '3075'
    Syntax error in string in query expression 'ID='1234567890'.

    Note that now there's a single quotes before ID (+ where's the rest of the sql string).

    As a note, ID is not a numeric field in the access database. Its in as a text-field. Now here's the biggie: this code works for me in my development PC and the query returns with the data in the db. This started happening on another laptop that I installed this application on all of a sudden and I am unable to reproduce this on my PC.

    Any help is appreciated.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    3,914

    Re: Run-time error 3075 - Syntax error in string in query expression VB6/MS-access

    Try this,
    Code:
    "SELECT * FROM TblData WHERE ID = '" & ID & "'"
    Use the ' instead, on both sides of ID

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    3

    Re: Run-time error 3075 - Syntax error in string in query expression VB6/MS-access

    Thanks for your response.

    Chr(39) adds the quotation (') on both sides of the ID.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,526

    Re: Run-time error 3075 - Syntax error in string in query expression VB6/MS-access

    Welcome to VBForums

    I just checked, and it seems that Chr(39) is equivalent to ' , so that is not the issue.

    Note that the quotation is missing at the end
    That seems to be the cause of the issue, but it does seem odd.

    Where is the ID value coming from, and could it possibly contain a Chr(0) at the end? (if so, you won't see it in the Watch window etc, and it will terminate the string)
    (+ where's the rest of the sql string).
    As SQL statements tend to get quite large, the error messages try to show only the relevant part.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    3

    Re: Run-time error 3075 - Syntax error in string in query expression VB6/MS-access

    You hit the nail on the head. It turned out that the ID that was returned from the source was null terminated and hence the quotation char could not be added at the end.

    Thanks a lot.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width