Results 1 to 8 of 8
  1. #1
    Keegan is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4

    AfterUpdate Event to INSERT new Record in 2nd table

    In MS Access 2010, I am using the after update event on a date field in the primary form to populate/insert a new record in the subform. But my SQL code is not working; please help.




    Private Sub Date_AfterUpdate()


    Dim strSQL As String


    strSQL = "INSERT INTO Comm_Poll_Data ([LCC]) VALUES('A') WHERE Mission.MissionID = Comm_Poll_Data.[Mission ID] AND Comm_Poll_Data.[LCC] IS NULL;"


    DoCmd.RunSQL strSQL


    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,521
    There are two valid formats:

    INSERT INTO...
    VALUES...

    and

    INSERT INTO...
    SELECT...
    FROM...
    WHERE...

    You've combined the two, which you can't do.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Keegan is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4
    Understood.
    strSQL = "INSERT INTO Comm_Poll_Data ([LCC]) VALUES('A');"
    When I try above code it still does not work.

  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,521
    What does "does not work" mean? Do you get an error, and if so what is it? What happens if you paste that SQL into a new query and try to run it? You'll often get a more descriptive error. Are there any required fields in the table that aren't being populated?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Keegan is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4
    I mean I cannot even get the AfterUpdate to fire. Its as if the code isn't even there.
    You stated to paste the SQL statement into a new query and try to run it; how can I do this for the AfterUpdate?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    2010 requires that either the db be in a Trusted Location or that you explicitly enable code. Have you done that? Is any code at all running? This is the after update event of a textbox? If so, are you trying to fire it by typing in a value and pressing enter?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Keegan is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    4
    I have explicitly enabled the code and no, its not executing at all. The AfterUpdate event resides in a date box -- after user enters the date or chooses it from the pop-up calendar, it should fire the event but I am not getting anything not even the debugger. I even entered a button to execute the same code, but that isn't working either. I am at a lost, but I greatly appreciate your help pbaldy.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here?
    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. Form AfterUpdate Event
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 09-09-2011, 09:20 AM
  2. AfterUpdate event help
    By 10 Gauge in forum Forms
    Replies: 11
    Last Post: 09-08-2011, 10:04 AM
  3. AfterUpdate event code error?
    By agripa86 in forum Programming
    Replies: 3
    Last Post: 08-12-2011, 09:12 AM
  4. how to created afterupdate event
    By Brigitt in forum Forms
    Replies: 2
    Last Post: 02-15-2011, 03:23 AM
  5. AfterUpdate event won't refresh subform!
    By Remster in forum Forms
    Replies: 16
    Last Post: 11-26-2010, 10:06 AM

Tags for this Thread

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