Results 1 to 4 of 4
  1. #1
    sovereign is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    30

    Insert into

    Afternoon,

    So I have some code that was working but now seems to show Syntax Error.

    If someone could help would be really helpful

    Code:
    Dim workreq As String
    workreq = "N/S/F: " & Me!Text771 & "mm," & "O/S/F: " & Me!Text782 & "mm," & "N/S/R: " & Me!Text785 & "mm," & "O/S/R: " & Me!Text788 & "mm," & "Spare: " & Me!Text791 & "mm"
    jetsql = "INSERT INTO fleet_Maintenance (Fc, FMx, FMmileage,) VALUES ('" & Me.txtFC & "', 'Check Sheet Completed test' & vbCrLf & workreq & vbCrLf & Me.Other & " ', '" & Me.txtFMmileage & "');"
    CurrentDb.Execute jetsql, dbSeeChanges  'dbSQLPassThrough
    Fc is a number as is me.txtFC
    FMx is text and numbers


    FMmileage is numbers

    im sure its so simple but I just cant seem to find it

    Regards

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    If mileage is a number, why did you quote it?

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    When creating SQL within vba, create a string variable. Then, assign your "SQL" to that string.
    Then, insert a Debug.print yourSQLvariableName to output the SQL that Access has rendered to the immediate window. It will show any syntax errors.

    eg.

    Code:
    Dim sSQL as string
    sSQL =  "INSERT INTO fleet_Maintenance (Fc, FMx, FMmileage,) VALUES ('" & Me.txtFC & "', 'Check Sheet Completed test' & vbCrLf & workreq & vbCrLf & Me.Other & " ', '" & Me.txtFMmileage & "');"
    
    Debug.Print sSQL
    ....
    I you don't know how to get to the immediate window,hit Ctrl G and view immediate window

  4. #4
    sovereign is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    30
    was trying to remember that debug.print code so simple but forgot it!

    Got it perfect thanks for all your help again

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Insert into where
    By Richie27 in forum Queries
    Replies: 31
    Last Post: 05-18-2012, 02:11 AM
  3. Insert into
    By glasgowlad1999 in forum Access
    Replies: 2
    Last Post: 10-14-2011, 02:38 PM
  4. SQL Insert into
    By jamin14 in forum Programming
    Replies: 15
    Last Post: 04-01-2010, 12:35 AM
  5. help with insert
    By jamie in forum Access
    Replies: 1
    Last Post: 11-16-2009, 06:02 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