Call a function on a subform from a common module

IfButOnly

Registered User.
Local time
Today, 22:23
Joined
Sep 3, 2002
Messages
236
I'm sure I have done this before but for the life on me i can't work it out now.

I can reference an object ok on the subform; can execute the forms' function from the common module when it is not a subform. Unfortunately, after 218 variations (possibly) I have not got the syntax to work when I try to execute the function on the subform.

I get the message - "the expression you entered has a function name that microsoft Access can't find."
-----------------------
Code:
Public Function fDelGame()
' this function is generally executed from a short cut menu. It, in turns,
' executes the function "fDeleteGame" which resides in the form code
' for fGames. fGames may be the subform source object of fMain - sfMain.
'
If fIsLoaded("fMain") Then
Forms.fMain.sfMain.Form.fDeleteGame ' this is the line i'm struggling with
Else
Forms.fGames.fDeleteGame
End If

End Function
Code:
-----------------------------
Any help would be appreciated.

Ta ... Peter
 
Last edited:
The subform must be referred to via the name of the subformcontrol on the main form, which is not necessarily the same as the SourceObject of that subformcontrol.

Code:
Forms.mainformname.subformcontrolname.Form.methodname

(A public function of an object is known as a "Method")
 
BTW fIsLoaded is unnecessary.

Access forms have the IsLoaded Property used like this:

Code:
CurrentProject.AllForms.formname.IsLoaded
 
Thanks Galaxiom for your quick reply. I tried as you suggested but still got the same problem.
I, of course, may be explaining or understanding incorrectly.
I have a form "fMain" which has a subform with name "sfMain" and the source object is "fGames". I have a method (thanks for that) within fGames called "fDeleteGame". It is this method that I am trying to execute from a common module function.
As I understood what you were telling me I modified the code as below:-
Code:
Public Function fDelGame()
'   this function is generally executed from a short cut menu. It, in turns,
'   executes the function "fDeleteGame" which resides in the form code for fGames.
'   fGames may be the subform source object of fMain - sfMain.
'
    If fIsLoaded("fMain") Then
        Forms.fMain.sfMain.Form.fDeleteGame ' this line is the problem
        Else
        Forms.fGames.fDeleteGame
    End If
End Function

I should mention that i'm using access 2002 & Windows Vista.

Any thoughts ... Peter
 
Last edited:
Found the problem. I couldn't see past the syntax and in one of the many variations I changed the menu - so it was the menu item not finding the function.

Thanks very much for your help Galaxiom and sorry to have wasted your time.

Peter
 
No worries Peter. Sometime we just need to confirm the track we are on is being followed correctly to realize that we are actually on the wrong track.
 

Users who are viewing this thread

Back
Top Bottom