Triggering a procedure in a form's module from a subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm relatively new at this sort of thing. Please excuse me if this is a
silly question:

I have a form with subforms on it. On the sub forms I use the .AfterUpdate
event to trigger a procedure (in each subform's module) called UpdateFields
which calculates some values for the subform's current record. Is it possible
to get this UpdateFields procedure to trigger another UpdateFields procedure
in the parent form?

Thanks in advance.
D
 
Yes.
First check whether the parent form is open - the subform may have been
opened in its own right.

Dim f as Access.form
Dim bOK as Boolean

bOK = False
For each f in Forms
If f.name=<Name of parent> then
bOK = True
Exit for
End if
next

'If it is Open then update the control
If bOK then
Forms(<Name of parent>).<Controlname> = Value
end if

Alternatively I like to have a global boolean variable for each form which
is set to True when the form is opened and False when it is closed. Saves
mucking around with the loops
You may also like to check out the Parent property

HTH
Terry
 
Thanks a lot Terry,

I found that I can access the parent's procedures (not just controls) from
the subform's class module by using the parent property.

I also have a form in my project that is hidden and I use that to hold any
global variable that the rest of my form modules need to use.

1. Is it possible to run procedures in that hidden form's module from other
(non-child) forms.
2. You have me intrigued - how do I declare a global variable that is
accessible from other non-child forms.

Thanks
D
 
I found the answers by trolling through previous posts! (as I probably should
have done in the first place)

declare required variables or procedures as public
then access by:

Forms!frmName.variablename
OR
Forms!frmName.procedurename

Thanks
D
 
Hello Derm
Sorry for the delay - I was not receiving the notification but this has been
fixed.
1. Is it possible to run procedures in that hidden form's module from other
(non-child) forms.
Yes. In the hidden form decale the FUNCTION you want to access as Public. To
access it call it like an ordinary function but use the name of the form with
it eg Call <Formname>!<FunctionName>
2. You have already got that.
Cheers
Terry
 
Thanks Terry

Terry said:
Hello Derm
Sorry for the delay - I was not receiving the notification but this has been
fixed.
1. Is it possible to run procedures in that hidden form's module from other
(non-child) forms.
Yes. In the hidden form decale the FUNCTION you want to access as Public. To
access it call it like an ordinary function but use the name of the form with
it eg Call <Formname>!<FunctionName>
2. You have already got that.
Cheers
Terry
 
Back
Top