1

I have two forms (in question here). frmContactList and frmContactDetails. frmContactList is a datasheet list of last names, first names, and e-mail addresses. The idea (which works and hasn't been a problem so far) is that when you double-click either the last name or the first name, the form frmContactDetails is opened to the specific record chosen on frmContactList. All this works just fine. Where I'm having the trouble (annoyingly) is I want it to OPEN frmContactDetails then CLOSE frmContactList. OPEN works fine, close doesn't happen until I close frmContactDetails, though.
I BELIEVE the error is with the fact that I started with a "prefab" Access template and went to editing it from there. I didn't create this project from scratch. Won't make that mistake again. Thought I'd save time. Yeah right...

Here's the DblClick() coding I'm using for the Last Name (First Name will be the same once I figure out the bug:

NOTE: I commented out the Form.Dirty and Macro Error code because it's part of that messy "prefab" Access stuff.

Private Sub Last_Name_DblClick(Cancel As Integer)
On Error GoTo Last_Name_DblClick_Err

    On Error Resume Next
'    If (Form.Dirty) Then
'        DoCmd.RunCommand acCmdSaveRecord
'    End If
'    If (MacroError.Number <> 0) Then
'        Beep
'        MsgBox MacroError.Description, vbOKOnly, ""
'        Exit Sub
'    End If

    DoCmd.OpenForm "frmContactDetails", acNormal, "", "[ID]=" & ID, , acDialog
    DoCmd.Close acForm, "frmContactList"

Last_Name_DblClick_Exit:
    Exit Sub

Last_Name_DblClick_Err:
    MsgBox Error$
    Resume Last_Name_DblClick_Exit

End Sub


Here are a few pictures of the design.

Simple design.
Just a quick image of the design of the data in question - proving there is an "ID" field.

Here frmContactDetails is opened (personal information is blacked out) showing frmContactList in the background not closed.

Image of both forms

2
  • Try changing the order of those 2 lines. In other words, CLOSE then OPEN. Commented Apr 22, 2019 at 14:06
  • @HansUp, that's something I could try, but frmContactDetails won't always open FROM frmContactList. @Brian - tried that and frmContactDetails doesn't find the proper record and errors out on loading. Commented Apr 22, 2019 at 14:10

1 Answer 1

4

When you open a form with WindowMode:=acDialog, then the code stops at this code line until the opened form is made invisible or closed. Just drop this parameter.

DoCmd.OpenForm "frmContactDetails", View:=acNormal, WhereCondition:="[ID]=" & ID
DoCmd.Close acForm, Me.Name

Note: Use WindowMode:=acDialog if you need the data entered in a dialog form at the call site. In this case, don't close the dialog form with Me.Close but instead hide it with Me.Visible = False, then get its data through Forms!fdlgMyDialogForm!TheData.Value and finally close it at the call site with DoCmd.Close acForm, "fdlgMyDialogForm".

Closing the current form with Me.Name is more robust than specifying the name as string constant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.