Consulting

Results 1 to 2 of 2

Thread: Advice needed !

  1. #1

    Advice needed !

    Hello,

    I have a program in VBA which manually imports information from an Excel file into an Access table (both 2003, and I am running on XP ), as the already present import option in Access does not suit my requirements.

    It all works fine, until it gets to a certain number of rows on the Excel file.
    On this Excel file, on row 1075, I get an error :
    Syntax error : Missing Operator in query :
    "SELECT * FROM Customer_Identifiers WHERE (((Customer_Identifiers.Field1) = 'EV') AND
    ((Customer_Identifiers.Field2)='AB10000525') AND ((Customer_Identifiers.Field3)='AB6014') AND ((Customer_Identifiers.Field4)='This is a description') AND ((Customer_Identifiers.Field5='AB10000525) AND ((Customer_Identifiers.Field6='F0631A' AND"

    And the message box does not indicate the rest of the query.
    When I choose to debug, I look at the string in which the query is stored, and all that is there is :
    "SELECT * FROM Customer_Identifiers WHERE (((Customer_Identifiers.Field1) = 'EV') AND
    ((Customer_Identifiers.Field2)='AB10000525') AND ((Customer_Identifiers.Field3)='AB6014') AND ((Customer_Identifiers.Field4)='This is a description') AND
    ((Cu

    Why is this happening ? Could it be a memory problem ?
    Any ideas are welcome.

  2. #2
    Ah...found the problem, but would still like an explanation on certain things.

    I thought it was a memory problem,which I thought weird as it shouldn't take so much memory, but as it always happened on line 1075, that was my initial thought.
    Turns out, when going through the excel file, I missed out an apostrophe, which would screw up the string for the query.
    My bad.

    however, could someone explain to me, while debugging, the whole string does not appear in the variables ? Would have helped me solve this problem sooner.

    Also, considering my code is :
    [VBA]sqlQuery2 = "SELECT * FROM Customer_Identifiers WHERE (((Customer_Identifiers.Field1) = '" & myRecordset.Fields(0) & _
    "') AND ((Customer_Identifiers.Field2)='" & myRecordset.Fields(1) & _
    "') AND ((Customer_Identifiers.Field3)='" & myRecordset.Fields(2) & _
    "') AND ((Customer_Identifiers.Field4)='" & myRecordset.Fields(3) & _
    "') AND ((Customer_Identifiers.Field5)='" & myRecordset.Fields(4) & _
    "') AND ((Customer_Identifiers.Field6)='" & myRecordset.Fields(5) & _
    "') AND ((Customer_Identifiers.Field7)='" & myRecordset.Fields(6) & _
    "') AND ((Customer_Identifiers.Field8)='" & myRecordset.Fields(7) & _
    "') AND ((Customer_Identifiers.Field9)='" & myRecordset.Fields(8) & _
    "') AND ((Customer_Identifiers.Field10)='" & myRecordset.Fields(9) & "'))"
    'Do query'
    Set myDataBase = CurrentDb.OpenRecordset(sqlQuery2)[/VBA]

    Is there a way to, if there is an error, reformat the myRecordset.Fields variables to strings without quotations marks, do the query, then continue with the rest of the code ?

Posting Permissions

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