Results 1 to 15 of 15
  1. #1
    selooselm is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    6

    Issue with AfterInsert Event on table not firing when inserting record from excel

    Hello!

    I'm having an issue where my code for AfterInsert event on my table isn't firing when a new record is inserted from excel.

    The event fires and works correctly when the record is inserted from within Access, however.

    Has anyone encountered this issue before and can point me in the right direction to get these events to fire?

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    How do you insert record from Excel - what is the code?

    I can't find any confirmation but I deduce that programmatically adding record does not trigger the data macro. I will have to do some experimentation later.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    selooselm is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    6
    Here's the excel vba to export to the database:

    Code:
    Sub UpdateDB()
    
    
    Dim db As Database
    Dim rs As Recordset
    Dim currID As Double
    Dim currTech As String
    Dim currTK As Single
    Dim currVC As Single
    Dim currWC As Single
    Dim currDoc As Single
    
    
    
    
    Application.Workbooks("temp_" & Format(Date, "mm_dd_yyyy")).Activate
    
    
    Set db = OpenDatabase(DBpath)
    Set rs = db.OpenRecordset("KPI", dbOpenTable)
    Set MS = ThisWorkbook.Worksheets("Main")
    
    
    currID = MS.OLEObjects("cmb_Tech").Object.List(MS.OLEObjects("cmb_Tech").Object.ListIndex, 1)
    currTech = MS.OLEObjects("cmb_Tech").Object.List(MS.OLEObjects("cmb_Tech").Object.ListIndex, 0)
    currTK = MS.OLEObjects("txt_TK").Object.Value
    currVC = MS.OLEObjects("txt_VC").Object.Value
    currWC = MS.OLEObjects("txt_WC").Object.Value
    currDoc = MS.OLEObjects("txt_Doc").Object.Value
    
    
        With rs
            .AddNew
            .Fields("ID") = currID
            .Fields("Tech Name") = currTech
            .Fields("Date Entered") = Date
            .Fields("Technical Knowledge") = currTK
            .Fields("Verbal Communication") = currVC
            .Fields("Written Communication") = currWC
            .Fields("Documentation") = currDoc
            .Update
        
            rs.Close
            Set rs = Nothing
            db.Close
            Set db = Nothing
        End With
        
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    My first attempt to build data macro is big failure. Doesn't matter how I enter new record - manually or with code - the data macro does not seem to run.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    selooselm is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    6
    Would it help to give you an edited copy of my database?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I doubt it. You could do this test which I was trying with my db. Insert a record to table using VBA code within Access:

    CurrentDb.Execute "INSERT INTO tablename(fieldname) VALUES('somevalue');

    If the AfterInsert event triggers then we know the issue is with the Excel code pushing data to Access.

    I am not familiar with the OLEObjects code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    selooselm is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    6
    I'll give it a shot. The OLEObjects is for working with activeX form controls on the worksheet.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I've never used ActiveX controls, not even in Excel.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by selooselm View Post

    ...AfterInsert event on my table isn't firing when a new record is inserted from excel...

    ...The event fires...when the record is inserted from within Access...
    You've actually answered the question yourself. As is true for many events that are associated with Controls, the Form_AfterInsert event does not fire if the Record is inserted through VBA code or Macro. Presumably, you can use the same strategy as we use for Control events, which is to explicitly Call the event, immediately after the Record is inserted.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I presumed 'AfterInsert event on my table' to mean a data macro (introduced with Access 2010).

    selooselm, let me know if that is wrong.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    selooselm is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    6
    Correct. This is a data macro tied to my table for after insertion of a new record.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Did you get the test done?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    selooselm is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    6
    Not yet. I just switched to a new laptop at work and am wrestling with the IT group to get Access installed again.

  14. #14
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I don't have 2010, but I wonder if, perhaps, the same rules apply to the AfteUpdate event of a Table, when a Data Macro is involved, as applies to the AfteUpdate event of a Control, which is to say if data is entered by way of keyboard it fires, but if entered through code (such as is the case when importing data from Excel) it doesn't?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    That's what I was thinking but I finally got data macro to do something. I ran CurrentDb.Execute code to insert a record and the data macro did trigger. Then I tested importing records with the wizard. The data macro triggered with every record that appended. Then I tested adding record through a recordset in Access VBA, also triggered data macro. Last test was to add new record from Excel VBA. This does not trigger the data macro.

    Think that settles the question.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. tab control - firing a page on-click event
    By Chuck55 in forum Programming
    Replies: 7
    Last Post: 05-01-2012, 09:57 AM
  2. Replies: 5
    Last Post: 03-02-2012, 04:43 PM
  3. Replies: 7
    Last Post: 01-02-2012, 06:19 PM
  4. Form level mouseup event not firing
    By Philhoop in forum Forms
    Replies: 3
    Last Post: 07-22-2010, 09:41 AM
  5. Replies: 1
    Last Post: 05-31-2010, 05:18 PM

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