Results 1 to 4 of 4
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,073

    Can't find a SQL syntax error

    Both arrays FT and NameArr are arrays DIM'd global to the current general module. They are loaded using the "Split" function elsewhere in the module. There's no problem with any of the elements. However, more often than not the FT array elements 5, 6 and 7 are zero length strings. I keep thinking that's why sql gets all excited. See the setting of strsql towards the bottom of the posted code. (I've set FT(5) and Ft(7) to "None", but that didn't seem to matter.)

    Before spending any time with this, here's one of the logged errors:

    "SQL execution error: 3134 Syntax error in INSERT INTO statement."
    "Family Name = Ackerman,Ron"
    "SQL STMT: INSERT INTO Families (FamilyName,FamilyAddress,FamilyCityState,FamilyZi p,FamilySalutation,FamilyPhone,FamilyE-Mail) Values(""Ackerman,Ron"",""645 J Street"",""GERING, NE"",""69341-3377"",""1"",""none"",""none"")"

    Notice the comma in the FamilyName "Ackerman,Ron". Could it be that's the problem? If so, any syntax suggestions to get around that?





    Code:
    Private Sub ImportFamily()
    Dim strFamilyName As String
    Dim strFamilyCtySt As String
    Dim strSpouseName As String
    Dim strSalutation As String
    Dim strsql As String
    Dim I As Integer
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=**=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' FT array elements:  Name(0),Addr(1),City(2),State(3),Zip(4),Phone1(5),Phone2(6),Email(7)
    ' NameArr array elements:  LastName(0) FirstName(1) conjunction(2) FirstName(3)
    ' We should be fairly "scrubbed" by the time we get here.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=**=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    On Error GoTo FamilyAddErr
    
        strFamilyName = NameArr(0) & "," & NameArr(1)
        
        If UBound(NameArr) = 3 Then
            strSpouseName = NameArr(3)
            strSalutation = "2"
        Else
            strSpouseName = ""
            strSalutation = "1"
        End If
        
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Make sure family doesn't already exist.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        If Not IsNull(DLookup("FamilyName", "Families", "[FamilyName] = """ & strFamilyName & """")) Then Exit Sub
      
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Okay, add the family to the Families table
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    strFamilyCtySt = FT(2) & ", " & FT(3)
    
    strsql = "INSERT INTO Families (FamilyName,FamilyAddress,FamilyCityState,FamilyZip,FamilySalutation,FamilyPhone,FamilyE-Mail)"
    strsql = strsql & " Values(""" & strFamilyName & """,""" & FT(1) & """,""" & strFamilyCtySt & ""","
    strsql = strsql & """" & FT(4) & """,""" & strSalutation & """,""" & FT(5) & """,""" & FT(7) & """)"
    
    
    CurrentDb.Execute strsql, dbFailOnError
    
    Exit Sub
    
    FamilyAddErr:
        Write #1, "SQL execution error: " & Err.Number & " " & Err.Description
        Write #1, "Family Name = " & strFamilyName
        Write #1, "SQL STMT: " & strsql
        Write #1, ""
        Exit Sub
    
    End Sub


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Hey Bill! First thing I notice is the inadvisable symbol in the email field name, requiring it to be bracketed. Fix that and see where we are.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,073
    Okay, that fixed it. This app is about 12-years old. It's amazing I haven't bumped my head on this issue long before this.
    Thanks,
    Bill
    (PS) Ought to be a bit toasty over your way. About 92 here.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help Bill! Pretty toasty, but the wife was in Vegas working for a week and it was really hot there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Can't find the syntax error in this SQL
    By FelicianoRa@coned.com in forum Programming
    Replies: 1
    Last Post: 02-14-2013, 09:04 AM
  3. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  4. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums