PDA

View Full Version : call subform.control.click



OTWarrior
04-10-2008, 02:32 AM
I am trying to call the function that runs in an OnClick event that is on a subform (the onclick moves the record to the next one)

I know how to reference a control from a subform and call its value etc, but how do you fire its events?

ben.oates
04-10-2008, 04:49 AM
Hi OTWarrior,

The best way to do this is to move the code you have written for the OnClick event into another procedure then call that from both your OnClick sub and any other procedures you need to.

Hope this helps.

Carl A
04-10-2008, 06:43 AM
From the help files:
You can use the SetFocus method to move the focus to a subform (subform: A form contained within another form or a report.), which is a type of control. You can also move the focus to a control on a subform by using the SetFocus method twice, moving the focus first to the subform and then to the control on the subform.

I haven't tested this on a subform but you can reference a control on another form by setting the focus to the form and then to the control and using the controls GotFocus event you can call the OnClick event.

Private Sub Command0_Click()
'Form2
Forms!Form1.SetFocus
Forms!Form1.Command1.SetFocus

End Sub
Private Sub Command1_GotFocus()
Call Command1_Click
End Sub

HTH

DarkSprout
04-10-2008, 07:55 AM
Also Remove the Private part of the Sub Name - this makes it availible for the whole database to call

ie. '// use either the forms name or a string
Call Forms("FormName").SubName
Call Forms(strFormName).SubName

Trevor
04-10-2008, 01:27 PM
I agree w/ Carl, and ben