Go back to original Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 3 forms that give the choice of going to One other form. I would like
to be able to have one button on that could enable the user to go back to the
form he came from( one of the 3 that he came from). I thought I would set a
variable when I leave the original and then Open that varaiable when I want
to go back to that form. I think I have my " wrong (in or out) or I should
be setting the variable in public.

So in each form as I leave(on click) I set FormName to the name of the form
that I am leaving .
Dim FormName As String
FormName = "frmInquiryPosting"

Then In the Other form (To get back ) I used the Cmd Wizard and changed the
name of the form I gave the wizard to FormName
stDocName = FormName
DoCmd.OpenForm stDocName, , , stLinkCriteria

It doesnt work. I hope I am Making sense.
 
NNlogistics said:
I have 3 forms that give the choice of going to One other form. I
would like to be able to have one button on that could enable the
user to go back to the form he came from( one of the 3 that he came
from). I thought I would set a variable when I leave the original
and then Open that varaiable when I want to go back to that form. I
think I have my " wrong (in or out) or I should be setting the
variable in public.

So in each form as I leave(on click) I set FormName to the name of
the form that I am leaving .
Dim FormName As String
FormName = "frmInquiryPosting"

Then In the Other form (To get back ) I used the Cmd Wizard and
changed the name of the form I gave the wizard to FormName
stDocName = FormName
DoCmd.OpenForm stDocName, , , stLinkCriteria

It doesnt work. I hope I am Making sense.

If you declare the variable FormName in any form's module, it won't be
known to any other form. I expect that's why your code won't work. One
possible solution is to define the variable as a global (Public)
variable in a standard module, not a form module. But you don't really
need to do that. In the Open event of any form, the form that
previously had the focus -- that is, the form from which the new form
was opened -- is still considered to to be the "active form", and you
can get its name from the Screen.ActiveForm.Name property. So you could
have code in each form's module like this:

'----- start of example code -----
Option Compare Database
Option Explicit

Dim mstrCallingForm As String

Private Sub Form_Open(Cancel As Integer)

' Capture the name of whatever form is
' currently active (if any).

On Error Resume Next
mstrCallingForm = Screen.ActiveForm.Name

End Sub

Private Sub Form_Close()

' If another form was active when this one
' was opened, reopen that form.

If Len(mstrCallingForm) > 0 Then
DoCmd.OpenForm mstrCallingForm
End If

End Sub
'----- end of example code -----
 
Back
Top