Results 1 to 2 of 2
  1. #1
    VFWMain is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2014
    Location
    Houston, TX
    Posts
    1

    Insert Into Select Where Issues

    I have been trying for hours to get this code to work, I have looked at countless websites and gained tidbits of info here and there.
    I have two tables, One is the main entry table (Safety Audits) for auditing and the other is to close an open audit (Closed Audits). What I need to do is to insert the data from Closed Audits into the Safety Audits.
    Why not use the UPDATE statement you may ask? There is no data to update in the two fields [DateClosed],[CAR]. So i have to use an insert statement.

    Below is the code:

    Dim CAD As Date ' Date Audit is to be closed
    Dim MainSql As String
    Dim CARE As String ' User entered filed to describe why audit is being closed
    Dim ADID As Long ' Entered Audit ID
    Dim AudSt As String ' Status of the Audit is not closed
    AudSt = "Closed"
    ADID = Me.txtID
    CAD = Format(Me.txtDateC, "mm/dd/yyyy")
    CARE = Me.txtRC


    MainSql = "INSERT INTO [tblAudits](DateClosed, CAR, Status) VALUES(#" & CAD & "# ,'" & CARE & "', '" & AudSt & "') SELECT([Audit ID], DateClosed, CAR) FROM [Closed Audits ]WHERE [tblAudits].[Finding ID] =" & Me.txtID & ");"


    I am now getting a error saying there is a missing ";" at the end of the statement.

    This is what I see in the immediate window.


    INSERT INTO [tblAudits](DateClosed, CAR, Status) VALUES(#3/11/2014# ,'Test', 'Closed') SELECT([Audit ID], DateClosed, CAR) FROM [Closed Audits ]WHERE [tblAudits].[Finding ID] =1505);

    Any and all help is greatly appreciated.

  2. #2
    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
    Not sure I'm following but see what this gives in the immediate window

    Code:
    MainSql = "INSERT INTO [tblAudits](DateClosed, CAR, Status)   SELECT([Audit ID], DateClosed, CAR) FROM [Closed Audits ]WHERE  [tblAudits].[Finding ID] =" & Me.txtID & ");"

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

Similar Threads

  1. Insert value and select ID
    By FinalByte in forum Access
    Replies: 2
    Last Post: 10-31-2013, 08:53 AM
  2. multi select issues
    By ACMC in forum Access
    Replies: 1
    Last Post: 07-26-2013, 03:42 PM
  3. INSERT with SELECT query.
    By goodguy in forum Queries
    Replies: 8
    Last Post: 09-23-2011, 10:38 AM
  4. select and insert using two seperate tables
    By benjammin in forum Queries
    Replies: 2
    Last Post: 02-20-2011, 04:52 PM
  5. INSERT INTO ... SELECT Subquery
    By TheDeceived in forum Programming
    Replies: 1
    Last Post: 10-19-2010, 09:29 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