Reputation: 129
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.
Here frmContactDetails
is opened (personal information is blacked out) showing frmContactList
in the background not closed.
Upvotes: 1
Views: 51
Reputation: 112352
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.
Upvotes: 4