Results 1 to 4 of 4
  1. #1
    nicolareina is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2021
    Posts
    6

    Syntax Errore "FROM"


    Hi guys this is my problem

    name form = test
    ___________________________
    i have a form and i would like to copy the single record into the new table

    Click image for larger version. 

Name:	error.jpg 
Views:	26 
Size:	175.0 KB 
ID:	49818

    this is my code
    Code:
    Private Sub cmdAddRecords_Click()
    
    
    On Error GoTo errHandler
    
    
    Dim strSQL As String
    
    
    strSQL = "INSERT INTO tblNewTable (RecordID, Field1) " _
        & " SELECT RecordID, Field1 FROM tblOldTable" _
        & "WHERE tblOldTable.RecordID = [Maschere]![test]![RecordID]"
    
    
    db.Execute strSQL, dbFailOnError
    
    
    Me.frmNewAttachment.Requery
    
    
    errExit:
        Exit Sub
        
    errHandler:
        MsgBox Err.Number & ": " & Err.Description
        Resume errExit
        
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Debug.Print strSQL and see if you can spot the error.

    I always do that before trying to use it.

    You likely need to concatenate [Maschere]![test]![RecordID]
    You can also copy the debug output and test in the QBE window ?

    I tend to build using
    strSQL = strSQL & " WHERE ..." etc
    Notice the space before each new string?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Code:
    db.Execute strSQL, dbFailOnError
    Where are you declaring and setting your db variable?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    I suppose the ID is a number, so bring it outside the " " string so Access can evaluate it

    Code:
    strSQL = "INSERT INTO tblNewTable (RecordID, Field1) " _
        & " SELECT RecordID, Field1 FROM tblOldTable" _
        & "WHERE tblOldTable.RecordID = " & [Maschere]![test]![RecordID]

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

Similar Threads

  1. Replies: 2
    Last Post: 03-02-2023, 09:25 AM
  2. Replies: 7
    Last Post: 03-19-2021, 05:54 PM
  3. Simple table relationships ("faces" to "spaces" to "chairs")
    By skydivetom in forum Database Design
    Replies: 36
    Last Post: 07-20-2019, 01:49 PM
  4. Replies: 3
    Last Post: 06-06-2018, 08:26 PM
  5. Replies: 1
    Last Post: 09-07-2015, 08:00 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