Results 1 to 2 of 2
2014-01-24, 08:45 #1
Best Practise: Determine behaviour when form closes
I have a form (frmSubmitterAdmin) and depending on how the form was called, I want different things to happen when the form is closed e.g. if the form was called from a button on the main menu, I want the form to close and the main menu to be re-opened but if the form was called from a double click action on a field on the form frmRegisterClaim, I want it to update that field on frmRegisterClaim with the value of the corresponding field on frmSubmitterAdmin.
Here is how I have accomplished this, but what I want to know is if there is a better way to accomplish the same effect.
On click event of button on main menu:
Private Sub btSubmitterAdmin_Click()
On Error GoTo btSubmitterAdmin_Click_Err TempVars.Add "tvarNewSubmitter", 0 TempVars.Add "tvarSubmitterMenu", "frmAdminDashboard" DoCmd.Close , "" DoCmd.OpenForm "frmSubmitterAdmin", acNormal, "", "", , acNormal btSubmitterAdmin_Click_Exit: Exit Sub btSubmitterAdmin_Click_Err: MsgBox Error$ Resume btSubmitterAdmin_Click_Exit End Sub
Private Sub lutClaimSubmitter_DblClick(Cancel As Integer) On Error GoTo lutClaimSubmitter_DblClick_Err TempVars.Add "tvarSubmitterMenu", "frmRegisterClaim" If Me.lutClaimSubmitter = 1 Then DoCmd.OpenForm "frmSubmitterAdmin", acNormal, "", "", , acNormal Else Dim SubmitterID As Integer SubmitterID = Me.lutClaimSubmitter DoCmd.OpenForm "frmSubmitterAdmin", , , "intSubmitterID =" & SubmitterID End If lutClaimSubmitter_DblClick_Exit: Exit Sub lutClaimSubmitter_DblClick_Err: MsgBox Error$ Resume lutClaimSubmitter_DblClick_Exit End Sub
Private Sub Form_Close() Select Case TempVars!tvarSubmitterMenu Case "frmAdminDashboard" DoCmd.Close , "" DoCmd.OpenForm "frmAdminDasboard", acNormal, "", "", , acNormal Case "frmRegisterClaim" Forms!frmRegisterClaim.lutClaimSubmitter.Value = intSubmitterID.Value DoCmd.Close , "" Case Else End Select End Sub
2014-01-26, 11:41 #2
- Join Date
- Jun 2001
- Crystal Beach, FL, Florida, USA
- Thanked 34 Times in 34 Posts
This seems reasonable. I use a similar method, except I use a global variable since I've used the technique long before we had TempVars. So my open statement would look like this:
gReturnToFormname = me.name
docmd.minimize 'Note: I generally do this, because when I come back to this form, I want to come back to a specific place in it.
When frmWhatever opens, I do this:
glocReturnToFormname = gReturnToFormName 'Note: glocReturnToFormname is at form-level variable
gReturnToFormname = ""
The advantage of this is that I can have an unlimited number forms that open (and can even stay open) and as each closes it knows which form to go back to since each has its own glocReturnToFormname. This could be a weakness in your method as you can really only open the single form. For example, on a search screen the user can double-click to open a customer record. On that screen, the user can double-click to open a screen for a particular property address. On the property screen, a double-click can open a specific Work Order. I can easily go up and down this "tree" and not lose my place.