tempcars to remember a closed for to reopen later

Hello,
is it possible to use tempvars to remember a form closing and use that to reopen the form later
Ernest GroggAsked:
Who is Participating?
 
Dale FyeCommented:
Usually, I don't close a form that calls my search form, I just popup the search form on top of the other form.

However, another way to handle this is to pass the searchform the name of the form that called it, during the OpenForm method.  
docmd.OpenForm "frmSearch", acNormal, , , , , me.name
docmd.close acform

Open in new window

Then use the Form_Close event of the search form to either open or set the focus to the form that opened it.  This would look something like:
Private Sub Form_Close

    is currentproject.allforms(me.OpenArgs).isloaded then
        Forms(me.OpenArgs).visible = true
        Forms(me.OpenArgs).setfocus
    Else
        docmd.openform me.OpenArgs, acviewnormal
    endif

End Sub

Open in new window

0
 
PatHartmanCommented:
If you want to simply log the fact that a form closed, do it in the form's unload event.  You can then check the tempvar to see if it was set.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can use TempVars for any number of things - they're really just an in-memory set of variables that can be globally referenced.

But you'd have to give more information about what you want to do. Opening a form is easy (just use DoCmd.OpenForm), but I assume you want to do something more - like open a form back to a specific record, or with a specific subset of records, perhaps.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Dale FyeCommented:
or, another reason for logging a form close operation might be to keep a stack of forms that were opened, and in what order.  If that is the case, you might want to consider a collection.
0
 
Ernest GroggAuthor Commented:
What I want to do is use a search form in several areas on my forms that go from section to section.

I want to reopen the last form when I close the search form.  So if tge search form was opened in one area it will reopen in that area.

Say frmOptions opens frmSearch, so closing frmSearch reopens from prions again

But if frmSearch was opened from frmOptions2 then when frmSearch closes it reopens frmOptions2

No matter where frmSearch opens the last form is reopened.
0
 
PatHartmanCommented:
I don't close forms either but I do hide them so that the user rarely ever sees more than one open form at a time.  I use the OpenArgs to reopen the calling form when the called form closes.  This allows unlimited nesting.  The one thing you need to be conscious of is reusing a form in an alternate path.  Since no history is actually kept, you can only follow one path back to the beginning.
Private Sub Form_Close()
On Error GoTo ErrProc
 
    If frm.Dirty Then
        DoCmd.RunCommand acCmdSaveRecord
    End If
    If IsNull(frm.OpenArgs) Then
        DoCmd.OpenForm "Switchboard"
    Else
        DoCmd.OpenForm frm.OpenArgs
    End If
  
ExitProc:
    Exit Sub
ErrProc:
    Select Case Err.Number
        Case 2102   'bad open args form name
            Resume ExitProc
        Case 2455   'happens for A2007 when unbound form references the Dirty property
            Resume Next
        Case Else
            MsgBox Err.Number & "--" & Err.Description
            Resume ExitProc
    End Select
End Sub

Open in new window

0
 
Ernest GroggAuthor Commented:
Fantastic,
thank you so much!
0
 
Ernest GroggAuthor Commented:
I am using this search form for multiple uses and changes from the search criteria chosen so that only certain forms open based on that search, like editing a customer, or order, or various data info.

I only need that form to remember the previous,  both work out great, just didn't see Pat's until after.. sorry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.