Results 1 to 2 of 2
  1. #1
    jbrickner is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2018
    Posts
    15

    Access Not Closing after Code is run as macro

    I have been finding that Access is not closing entirely when a specific code is run during use. Basically, once this code is run, when Access is closed it will remain as a background process in the task manager. My research has suggested this may be due to a recordset not being closed correctly. However, this only happens when the code is run from a command-button-macro on a form. If I run the code entirely from the instant window Access will close just fine. But when I run the same code through a "RunCode" macro using information on the form, it triggers this bug. I have included the code for reference, but none of the code called internally as I have already been through them. If you find that you need it, though, I can add it later.

    Here is the code (please excuse my messy setup and I will clarify anything not commented if necessary):

    Code:
    Function NewInspectionList(SO, PN, Optional PrimaryInspector)'Generates a list of inspections based on PN.  Identifies each inspection as linked to SN
    SN = GenerateSerialNumber(SO)
    RN = SerialBreakdown(SN, "RN")
    
    
    If SN = "" Or IsNull(SN) Then
        Exit Function
    ElseIf SNexists(SN) = True Then
        If IsOpen("StandardFinalAudit") = True Then
            GoTo ResumeNew
        Else
            Exit Function
        End If
    ElseIf IsOpen("StandardfinalAudit") = False Then
        Exit Function
    End If
    
    
    If IsMissing(PrimaryInspector) = False Then
        StoreSerial SN, SO, RN, PN, PrimaryInspector
        Forms!StandardFinalAudit!cmbFirst = PrimaryInspector
    Else
        StoreSerial SN, SO, RN, PN
    End If
    
    
    ResumeNew:
    'Autofill Audit Form
    Forms!StandardFinalAudit!txtSerial = SN
    Forms!StandardFinalAudit!txtPN = PN
    Forms!StandardFinalAudit!txtrn = RN
    Forms!StandardFinalAudit!txtSO = SO
    Forms!StandardFinalAudit!txtDate = Date
    
    
    'If Folding, run foldinglist
    If IsFoldingBlade(PN) = True Then
        FoldingList SN, PN
        Exit Function
    End If
    
    
    
    
    Dim NILc As ADODB.Connection
    Dim NILs As New ADODB.Recordset
    Set NILc = CurrentProject.Connection
    NILs.ActiveConnection = NILc
    NILs.Open "Links", , adOpenKeyset, adLockOptimistic
    NILs.Filter = "PartNumber = '" & PN & "'"
    
    
    If NILs.EOF And NILs.BOF Then
        GoTo CloseNIL
    Else
        NILs.MoveFirst
    End If
    
    
    While Not NILs.EOF
        AddInspection SN, PN, NILs.Fields("Inspection")
        NILs.MoveNext
    Wend
    
    
    
    
    CloseNIL:
    Forms!StandardFinalAudit.Filter = "SerialNumber = '" & SN & "'"
    
    
    If Err <> 0 And msg = "" Then
        ErrMsg Err.Description, "NewInspectionList"
        Err = 0
    ElseIf Err <> 0 And msg <> "" Then
        ErrMsg Err.Description, "NewInspectionList (" & msg & ")"
        Err = 0
    End If
    
    
    Set NILc = Nothing
    NILs.Close
    NILs.ActiveConnection = Nothing
    End Function


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Why bother with macro if you are using VBA anyway? I never use macros. What happens if you call function from VBA?
    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. Macro fails on closing form
    By Lou_Reed in forum Access
    Replies: 6
    Last Post: 07-17-2017, 01:35 PM
  2. Replies: 3
    Last Post: 11-30-2016, 09:02 AM
  3. Run Code on Closing of DB
    By guillermoftw in forum Access
    Replies: 1
    Last Post: 12-16-2014, 11:48 AM
  4. Error Message When Closing a Form w/ Macro
    By KCC47 in forum Programming
    Replies: 8
    Last Post: 11-14-2014, 03:35 PM
  5. Help with access code (macro?) please
    By visidro in forum Programming
    Replies: 10
    Last Post: 03-15-2013, 05:56 PM

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