Using form IDs in event procedures

P

Phil Hood

Hello,

Is it possible to use the name of a form in an expression
written for an event procedure?

To illustrate, imagine an application has 3 forms A, B and
C.

A & B both link to C via a command button.

What I want to code is an event procedure for C:

If the previous form was A, then do something
If the previous form was B, then do something different

Is there a way of doing this?

Thanks in advance.

Phil.
 
M

Marshall Barton

Phil said:
Is it possible to use the name of a form in an expression
written for an event procedure?

To illustrate, imagine an application has 3 forms A, B and
C.

A & B both link to C via a command button.

What I want to code is an event procedure for C:

If the previous form was A, then do something
If the previous form was B, then do something different


The standard way for a form to keep track of the form that
opened it is to use the OpenForm method's OpenArgs argument.
For example, form A can open form C using
DoCmd.OpenForm "C", OpenArgs:= "A"

So form C's code can test this way:

If Me.OpenArgs = "A" Then
'do form A stuff
ElseIf Me.OpenArgs = "B" Then
'do form B stuff
Else
'do stuff when opened from somewhere else
End If
 
G

Guest

Many thanks

-----Original Message-----



The standard way for a form to keep track of the form that
opened it is to use the OpenForm method's OpenArgs argument.
For example, form A can open form C using
DoCmd.OpenForm "C", OpenArgs:= "A"

So form C's code can test this way:

If Me.OpenArgs = "A" Then
'do form A stuff
ElseIf Me.OpenArgs = "B" Then
'do form B stuff
Else
'do stuff when opened from somewhere else
End If
 

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