Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA question

Status
Not open for further replies.

ds2728

Programmer
Jul 18, 2001
50
0
0
US
Hello,

I have a question on how to tell which form called another form.

On form 1 when I select option "A", I open form 2 for data input. Once form 2 opens I would like to know how to figure out that form 1 was the form I was in before opening form 2.

Form 2 is a multi purpose form that I intend on calling from many different forms, so I would like to know which form called form 2.

Thank you for your time and assistance.

Dave
 
You can use the OpenArgs property of the form that you are opening. It can be set when the form is opened using this statment:

docmd.OpenForm "Form Name To Open",acNormal,,,,,"Form Name that Opened it"

In your example it would be:
docmd.OpenForm "Form 2 Name",acNormal,,,,,"Form 1 Name"

Then when you close Form 2, you can check the OpenArgs value to see what form opened it.
Pat B
 
Try the following..

You are calling frmTargetForm from frm1.

Include a command button on all your forms, which you click to open the Target Form. Use the following code for the OnClick event

Public Sub OpenTargetForm_Click()
Call DisplayTargetForm("frmTargetForm", Me.Name)
End Sub

In the standard module, write a procedure ...

Public Function DisplayTargetForm(TargetForm As String, PreviousForm As String) As String

DoCmd.OpenForm "frmTargetForm", acNormal
MsgBox "The Form That Opened this Form is " & PreviousForm

End Function

Hope this helps..

vr

 
OpenArgs is one easy way to do this. But if you're already using that for something you could make a form-level variable that gets set immediately after you open the form--as long as you're not opening it in dialog mode.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access databases since 1995.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top