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