Results 1 to 2 of 2
  1. #1
    New Lounger Ensemble's Avatar
    Join Date
    Apr 2013
    Thanked 1 Time in 1 Post

    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
        Exit Sub
        MsgBox Error$
        Resume btSubmitterAdmin_Click_Exit
    End Sub
    On double click event for field on frmRegisterClaim:
    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
            Dim SubmitterID As Integer
            SubmitterID = Me.lutClaimSubmitter
            DoCmd.OpenForm "frmSubmitterAdmin", , , "intSubmitterID =" & SubmitterID
        End If
        Exit Sub
        MsgBox Error$
        Resume lutClaimSubmitter_DblClick_Exit
    End Sub
    On close event for frmSubmitterAdmin:
    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

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Crystal Beach, FL, Florida, USA
    Thanked 40 Times in 39 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 =
    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.
    docmd.openform "frmWhatever"

    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.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts