The command:
DoCmd.Close acForm, lstrParentName, acSaveNo
in a combo box wrapper class (i.e., a class module that assigns a combo box object to a combo box variable declared WithEvents) consistently hard-crashes Access and I can't figure out why.
Context:
- The form is bound to a form wrapper class (clsFrm), which binds its controls to control-specific control wrapper classes (e.g., clsCbo).
- clsCbo sinks events for bound combo boxes, including OnDblClick.
- clsCbo binds a secondary combo box wrapper that encapsulates functionally related code.
- clsCbo.mCbo_DblClick() calls a nav procedure (nSuper()) that opens another form and closes the current one with
DoCmd.Close acForm, lstrParentName, acSaveNo, which causes Access to hard crash / fail / involuntarily shut down.
What's baffling is:
- The nav procedure runs without error and hits its exit procedure.
- The source / originating form closes and all its form and control wrappers hit their Class_Terminate() procedures without error.
- The destination form wrapper hits its binding method and subforms begin to load.
- Closing the form manually by clicking on its window's "X" button in the upper-right causes no difficulty.
But still, Access crashes. Nevertheless:
- Comment out the DoCmd.Close command and no problem.
- Skip binding the secondary combo box wrapper and no problem.
Any ideas what's up?
nSuper() is as follows:
Private Sub nSuper()
' Method to navigate from cboSuper~ID to the entity form.
' Dependencies:
' - mstrPath declared in Class_Initialize()
' - stdObjectTests.IsSubform()
' Dependants:
' - mCbo_DblClick
On Error GoTo ErrorHandler
200 Dim cboMe As ComboBox
210 Dim frmMe As Access.Form
220 Dim intPK As Long
230 Dim strDest As String
240 Dim strEnt As String
250 Dim strFld As String
260 Dim strPK As String
270 Dim strRS As String
280 Dim strWHERE As String
' Derive the filter criterion from the control:
290 Set cboMe = mCbo
310 intPK = cboMe.Value
' Derive Entity from Form.RecordSource:
320 Set frmMe = mParent
350 strRS = frmMe.RecordSource
370 strEnt = Right(strRS, Len(strRS) - 3)
' Compose the destination Form.Name from Entity:
400 If strEnt = "Party" Then
410 strDest = "frmFirm"
420 Else
430 strDest = "frm" & strEnt
440 End If
' Compose the filter:
460 strPK = strEnt & "ID"
480 strFld = "tbl" & strEnt & "." & strPK
500 strWHERE = strFld & " = " & intPK
510 If strDest = frmMe.Name Then
' Re-filter the current form if it is the entity form:
520 frmMe.Filter = strWHERE
530 frmMe.FilterOn = True
540 Else
' Otherwise, open the entity form:
550 DoCmd.OpenForm strDest, acNormal, , strWHERE
' Close the current form or its parent:
' - Either may crash Access:
560 If IsSubform(frmMe) Then
570 DoCmd.Close acForm, frmMe.Parent.Name, acSaveNo
580 Else
590 DoCmd.Close acForm, frmMe.Name, acSaveNo
600 End If
610 End If
ExitProcedure:
913 Close lintFF
914 Set lFso = Nothing
Set cboMe = Nothing
Set frmMe = Nothing
Exit Sub
ErrorHandler:
890 Resume ExitProcedure
End Sub 'nSuper()
Form_Unloadhandler in classes referencing it may not fire (if classes have a circular reference and the form is closed through normal closure) or Access will hard-crash (if the form is deallocated before the classes referencing it)