! Calling a Public Sub from another Form !

W

Wembly

Hi,

I can't figure out what the convention is for calling a
public sub procedure residing in one form from another
form.

The help file suggests the following, but it appears to
always run the Form_Open event again (which I don't want
to do).

Dim frm as New form_frmName
Call frm.publicSubName

I know how to call a variable and a control from another
form, but how does one call a sub routine from another
form?

Thanks in advance,

Wembly
 
S

Sandra Daigle

Hi Wembly,

the statement:

dim frm as New Form_frmName

Is a method of opening a new instance of the form named frmName - this is
why the Form_Open event is executing.

If "frmName" is open, then you can run a public sub using the following
statement:

forms!frmName.publicSubName

If you want a form variable you would say:

dim frm as Form
set frm=forms!frmName
frm.publicSubName

A form variable is useful and efficient if you need to make multiple
references to forms!frmName. If you only have the one reference, stick with
the forms!frmName reference instead.
 
G

Guest

I used:

Call forms!frmName.publicSubroutine

This did not allow me to compile properly.

If I remove the Call, the statement is accepted by the
compiler.

What is the general rule for using the Call reserved word?

-----Original Message-----
Hi Wembly,

the statement:

dim frm as New Form_frmName

Is a method of opening a new instance of the form named frmName - this is
why the Form_Open event is executing.

If "frmName" is open, then you can run a public sub using the following
statement:

forms!frmName.publicSubName

If you want a form variable you would say:

dim frm as Form
set frm=forms!frmName
frm.publicSubName

A form variable is useful and efficient if you need to make multiple
references to forms!frmName. If you only have the one reference, stick with
the forms!frmName reference instead.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Hi,

I can't figure out what the convention is for calling a
public sub procedure residing in one form from another
form.

The help file suggests the following, but it appears to
always run the Form_Open event again (which I don't want
to do).

Dim frm as New form_frmName
Call frm.publicSubName

I know how to call a variable and a control from another
form, but how does one call a sub routine from another
form?

Thanks in advance,

Wembly

.
 
S

Sandra Daigle

Interesting - I don't know why 'Call forms!frmName.publicSubroutine' doesn't
work. All of the following do work:

Dim frm As Form
Set frm = Forms!frmName
Forms!frmName.publicSubroutine
Forms("frmName").publicSubroutine
Call frm.publicSubroutine
Call Forms("frmName").publicSubroutine
'this one gets a syntax error
'Call Forms!frmName.publicSubroutine

I rarely use the call keyword and I am unclear about when it is required.
Let me do so checking - I'm curious about this and about why the one syntax
gets a compile error.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

I used:

Call forms!frmName.publicSubroutine

This did not allow me to compile properly.

If I remove the Call, the statement is accepted by the
compiler.

What is the general rule for using the Call reserved word?

-----Original Message-----
Hi Wembly,

the statement:

dim frm as New Form_frmName

Is a method of opening a new instance of the form named frmName - this is
why the Form_Open event is executing.

If "frmName" is open, then you can run a public sub using the following
statement:

forms!frmName.publicSubName

If you want a form variable you would say:

dim frm as Form
set frm=forms!frmName
frm.publicSubName

A form variable is useful and efficient if you need to make multiple
references to forms!frmName. If you only have the one reference, stick
with the forms!frmName reference instead.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Hi,

I can't figure out what the convention is for calling a
public sub procedure residing in one form from another
form.

The help file suggests the following, but it appears to
always run the Form_Open event again (which I don't want
to do).

Dim frm as New form_frmName
Call frm.publicSubName

I know how to call a variable and a control from another
form, but how does one call a sub routine from another
form?

Thanks in advance,

Wembly

.
 

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