on current of a different form

abenitez77

Registered User.
Local time
Today, 10:47
Joined
Apr 29, 2010
Messages
141
I want to call the "On Current" event of another form.

I have a parent(mainform) form and then I have a subform(CurrentForm) and in that subform(CurrentForm) I have another subform(mysubtab01). From the mySubTab01, I want to call the On Current of the parent form. How can i do this?

This is an example of how I am setting the record source of the deepest subform where I want to call the parent on current from:

Forms(mainform)(CurrentForm)(mySubTab01).Form.RecordSource = "Select * from subQrytab03"
 
I want to call the On Current of the parent form

Is that the parent form (CurrentForm) or the parent form (mainform)?

OnCurrent event occurs just before showing the first record or the next record. I wonder why you'd want to do it.

I would put all the coding in the OnCurrent event in the parent form into a separate function which is called by OnCurrent event or from the parent's form OnTimer and then set the parent's TimerInterval by
Me.parent.TimerInterval = 20
or
me.parent.parent.TimerInterval = 20
 
Actually, I want to call the On current of another subform from the same parent.

parentform - > Subform_A

parentform - > Subform_B

parentform - > Subform_B -> Subform_C

I want to call the On Current of Subform_A from Subform_C
 
Me.parent.parent!Subform_A.Form.Timerinterval =20

In Subform_A OnTimerEvent
me.timerinterval = 0
call Form_Current
 
Subform_A is a variable that has the name of the subform. So how would the syntax be?
 
Code:
Me.parent.parent![TheNameOfTheSubFormObjectInTheParentForm].Form.Timerinterval =20
 
Tried this:
Me.Parent.Parent!(TopForm).Form.OnCurrent

got an error:
"The expression you entered has an invalid reference to the parent property"
 
If you use () then take away !. If you use [] as Cronk shows you then the use of ! is correct
Code:
Me.Parent.Parent[B][COLOR=Red]!([/COLOR][/B]TopForm[B][COLOR=Red])[/COLOR][/B].Form.OnCurrent
Correct is:
Code:
Me.Parent.Parent(TopForm).Form.OnCurrent
 
If you use () then take away !. If you use [] as Cronk shows you then the use of ! is correct

Just to clarify.

Using square brackets would only be correct if they enclosed the actual name of the control being referred to. You cannot use a variable name in there.

Parentheses are used to enclose a string representing the name of the control. This can be a variable.

Either way, for the expression to work, the Current Event Procedure would need to be converted to a Public Sub, otherwise it would not be addressable from outside the module.

Personally I would avoid making the Current Event public. Instead I would create another Public procedure with a meaningful name that describes what it actually does.

I would call this form outside and also from the Current Event of the form.
 
I get an error when i try the error below, "The expression you entered has an invalid reference to the Parent property"

TopForm = "Dyn_" & Trim(str(Project_ID)) & "_SubFrmTab05Main"

Me.Parent.Parent(TopForm).Form.Oncurrent

I also tried:
Me.Parent.Parent!["Dyn_" & Trim(str(Project_ID)) & "_SubFrmTab05Main"].Form.OnCurrent

same error
 
What is the exact name of the procedure you are trying to run? OnCurrent is not the name of method of a form, it is the property you set to indicate what code runs when the Current Event is raised by the form. If you set the OnCurrent property to "[Event Procedure]", then, by default, a sub routine called Form_Current() will be executed, if it exists. If you are trying to run the Form_Current procedure of a different form, it needs to be Public . . .
Code:
[COLOR="Blue"]Public[/COLOR] Sub Form_Current()
[COLOR="Green"]   'handles the current event of the form[/COLOR]
End Sub
. . . and then to call that routine, you'd use code like . . .
Code:
[I]object[/I].Form_Current
. . . where object is an instance of the form that contains that said Public Form_Current sub routine, but this should be unusual, since the current event is designed for the form that raises it to do it's own housekeeping. Maybe you need the form to expose some other Public Sub you can call . . .

But what may be worthwhile is to back up a little and describe what overall job you are trying to accomplish by explicitly calling Form_Current() of a form two levels up in the subform hierarchy. My bet is that if we understand that, we may be able to offer a better overall way to accomplish your goal that sidesteps this fragile chained reference.

Hope this helps,
 
I finally got it to work. I did set the on current to a public, but what did it was this line below. I only needed .Parent once

Me.Parent(TopForm).Form.Form_Current


Thanks!
 
I'm glad you got it working.

However, you wrote
parentform - > Subform_A

parentform - > Subform_B

parentform - > Subform_B -> Subform_C

I want to call the On Current of Subform_A from Subform_C

To get to the parent form, and thence to Subform A from Subform C, Parent is required twice so I doubt your original statement of the situation was accurate.
 

Users who are viewing this thread

Back
Top Bottom