Results 1 to 4 of 4
  1. #1
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141

    I am using code to duplicate Record on form and subfom - getting Syntax error

    Found this code @ http://allenbrowne.com/ser-57.html
    I have a form with subform for entering data and set up a CmdDupe button
    I get the error message : Syntax error in Insert into


    Code:
    'Duplicate the related records: append query.
                If Me.[10SubformEquipment].Form.RecordsetClone.RecordCount > 0 Then
                    strSql = "INSERT INTO [10SubformEquipment] (TicketID, EquipmentID, Note) " & _
                        "SELECT " & lngID & " As TicketID, EquipmentID, Note " & _
                        "FROM [10SubformEquipment] WHERE TicketID = " & Me.TicketID & ";"
                    DBEngine(0)(0).Execute strSql, dbFailOnError
    and the line
    Code:
        DBEngine(0)(0).Execute strSql, dbFailOnError
    is highlighted...

    Can anyone see what is wrong?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It looks OK.

    I just used that code (today), but since the dB was in MDB format, I had to go to TOOLS/REFERENCES (in the IDE) and add a reference to Microsoft DAO 3.6 Object Library.

    Otherwise, you might add a "Debug.Print strSQL" statement before the DBEnging line...

  3. #3
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    I tried the Debug line - I get the same error
    When I tried to add the DAO 3.6 reference I got error that it conflicts with current reference.
    I have Visual Basic, Microsoft Access 14.0 Object Library, OLE Automation, Microsoft Office 14.0 Access Database..., Microsoft Outlook 14.0... References

  4. #4
    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,870
    It may be some issue with syntax, but if Steve uses it I guess not.
    And it shows up in intellisense when I tried it.

    You could do the traditional

    Dim myDb as dao.database

    set myDb = currentdb
    MyDb.Execute strSql, dbFailOnError
    Last edited by orange; 02-13-2015 at 10:21 AM. Reason: spelling

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

Similar Threads

  1. Replies: 1
    Last Post: 11-21-2013, 12:17 PM
  2. Syntax Error in my Query Code
    By PPat in forum Queries
    Replies: 5
    Last Post: 04-19-2013, 03:12 PM
  3. Replies: 1
    Last Post: 02-21-2013, 12:27 PM
  4. Replies: 1
    Last Post: 09-08-2012, 05:51 AM
  5. Duplicate Check code with Run-Time error '3079'
    By viper in forum Programming
    Replies: 5
    Last Post: 10-18-2010, 10:12 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