How to determine the originating form?

A

Amit

Hi,

I have formA which can be opened through two other forms,
formB and formC, using buttons. How can I determine in
formA which form opened it (formB or formC)?

Thanks!

-Amit
 
G

Gary Miller

Amit,

You can do this by passing the name of the form opening it
by using the OpenArgs property of the OpenForm method that
is opening the form. From Access97 Help...

Gary Miller
Sisters, OR

You can use the OpenArgs property to determine the string
expression specified by the openargs argument of the
OpenForm method that opened a form.

Setting

This property is available only by using a macro or by using
Visual Basic with the OpenForm method of the DoCmd object.
This property setting is read-only in all views.

Remarks

To use the OpenArgs property, open a form by using the
OpenForm method of the DoCmd object, and set the openargs
argument to the desired string expression. The OpenArgs
property setting can then be used in code for the form, such
as an Open event procedure. You can also refer to the
property setting in a macro, such as an Open macro, or an
expression, such as an expression that sets the
ControlSource property for a control on the form.

For example, suppose that the form you open is a
continuous-form list of clients. If you want the focus to
move to a specific client record when the form opens, you
can set the OpenArgs property to the client's name, and then
use the FindRecord action in an Open macro to move the focus
to the record for the client with the specified name.
 
G

Gary Miller

Sure, if you want, although there it is usually better to
keep it on the newsgroup so that others benefit.

Gary Miller
Sisters, OR
 
S

Shadow

Use the Tag property of the form.

when you open your form by clicking a button in form B, change the tag
property to FormB
DoCmd.OpenForm "FormA"
Forms!FormA.tag= "FormB"

when you open your form by clicking a button in form C, change the tag
property to FormC
DoCmd.OpenForm "FormA"
Forms!FormA.tag= "FormC"

Later, In FormA you can refer to FromA tag to decide what you will do
With Me
IF .tag= "FormB" then
...........
ElseIF .tag = "FormC" then
..........
end if
end with

Shadow
 
A

Albert D. Kallal

Actually, no tag property is need.

Further, no openargs is needed either!

While both of the above ideas will work, you can simply pickup the name of
the pervious form in the on-open event. In fact, you can grab the previous
form name as late as the on-load even. Hence, the following works well


Option Explicit
dim frmPrevious as form


Then, in the on-open.


set frmPrevious = screen.ActiveForm


Now, anywhere in code, you can use fields, properties and even code of the
previous from

msgbox "calling form = " & frmPrevious.Name

frmPrevious!LastName = "bla bla bla"

frmPrevious.Refresh

Or, even call custom code or methods from that previous form like:

frmPrevous.MyRefresh

Since I create quite a few custom menu bars, then I don't have to worry
about using open args, or even setting the tag property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top