identifying the form that has lauched a form

G

Guest

Hi,

I would like to be able to identify the form that loaded a particular form
so I can do refreshes and updates to the correct form, is there an easy way
of doing this?

I was going to pass a paramater on launch to identify the calling form and
store this in a variable but no quite sure how to do it. The code to launch
the form is below.

DoCmd.OpenForm ("formname")
 
W

Wei Lu

Hi smarty,

Thank you for your posting!

You could use the following code to get the Form object:

Forms("formname")

And then, you could use the Refresh function of this object.

Here is the article for your reference:

Form Object [Access 2003 VBA Language Reference]
http://msdn.microsoft.com/library/en-us/vbaac11/html/acobjForm_HV05186308.as
p

Hope this will be helpful!

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks for the posting but I don't think that helps me. To explain my
problem better I am launching a common popup form form several initiating
forms. I need to be able to identify on each occasion which form called it
so I can run code specific to the initiating form to update its field and
refresh the form.

Example

Form1 >>> opens >>>> PopupForm1
Form1 <<< updatedby <<<< PopupForm1

Form2 >>> opens >>>> PopupForm1
Form2 <<< updatedby <<<< PopupForm1

I could just have several copies of the same popup form but I don't want to
have to maintain too many versions, hence I need to have a way of identifying
the calling form.

Any ideas?
 
B

Bonno Hylkema

If your second form is a dialog form you can use the following code in the
second form with the On Open event:
FormName=Screen.ActiveForm.Name
If you use a later event Screen.ActiveForm.Name will show the name of the
second form!

Another method is to open the second form with args: DoCmd.OpenForm
("formname",,,,,OpenArgs)
In the On Open event of the second form you use:
FormName = Me.OpenArgs

This second method is less general than the first method. You have to hard
code the OpenArgs.

Regards, Bonno Hylkema
 
W

Wei Lu

Hi smarty,

Thank you for the your clarification.

Have you tried the suggestion Bonno provided?

You could use the second method. I tested on my side and got the Formname
in the second form.

Here is the code in the calling form:

'Sample code:

Dim arg As String

arg = Me.Name

DoCmd.OpenForm "your form name", , , , , , arg


Here is the code in the sub form:

Private Sub Form_Open(Cancel As Integer)

MsgBox Me.OpenArgs

End Sub


Hope this will be helpful!


Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi,

I have tried the first solution Bonno gave and this only returns the name of
the second form and I was after the name of the form that lauches the second
form.

The open args method is the one I origionally tried to use to pass the
information but when ever I try to use it I get a visual basic complile
error: expected:=

The code that causes this is below.
Dim arg as string
arg = "form1"
DoCmd.OpenForm ("frm_returns_transmitters",,,,,, arg)
 
G

Guest

Bonno,

Thanks for the reply I don't think the first method is suitable as I am
trying to identify the first form form the second form (popup) the first form
launched. I tried running this code on the second form and it just returned
the formname of the second form not the first.

The second method you mentioned is more suitable but comes up with an error
as mentioned on the reply to Wei Lu. I was wondering if this method would
work as I am using forms bound to stored procedures?
 
S

Sylvain Lafontaine

Why not add a public variable or property on the second form and set this
value to the name (or the object) of the form that lauch it right after the
call to the DoCmd.OpenForm?
 
G

Guest

I have tried doing this but the public variable is null when read back. The
onlyway I know of doing this is by setting up a seperate module with a public
variable that both forms can reference.

How do I reference the public variable in that form?

This does also seem a bit messy as I prefer to use message passing and
encapsulation where possible but if it works then I will be happy.

Thanks for the reply
 
S

Sylvain Lafontaine

First, the command « DoCmd.OpenForm "Form12", , , , , , arg » will work but
only if you don't put () like in « DoCmd.OpenForm ("Form12", , , , , ,
arg) ».

Second, I didn't have any trouble reading back the value of a public
variable. However, this value were not available in the second form for the
On_Open() and On_Load() events because because DoCmd.OpenForm have not yet
returned until the form is fully displayed. However, I had not trouble
accessing thereafter from a command button.
 
W

Wei Lu

Hi smarty,

Sylvain's suggestion is right, you don't need to put () and you need to use
the OpenForm method like this:

DoCmd.OpenForm "your form name", , , , , , arg.

Hope this will be helpful!

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei Lu [MSFT]

Hi smarty,

I would like to know have you resolved this issue or not. If you need any
help, please do not hesitate to let us know.
Thank you!

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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