Command Button MainForm to refer to subform button

S

slagg7575

Hello all!,

I have a slight difficulty with my form and subform. Main form is
Patient Information(Name, Birth, etc), and subform is Patient
details(test results, weight, etc). I would like all my command bottons
to rest on the Mainform. The problem I have is, how do I create or
refer to a control button on the subform, from the mainform. Like I
want a print button that prints, but the button is rested on the
subform, I want the user to click the main form print button and refer
to the print button on the subform, along with other controls via
Mianform---->subform as well.

Thanks,
 
A

Allen Browne

For the basics, see:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html
Particularly, the article explains the ".Form" bit is correct for all
versions, but particularly important in A2003.

If you are actually trying to execute the code in the Click event of the
button named Button1 in the subform named Sub1, you would need to remove the
Private keyword from the declaration line in the subform's module, i.e. from
this line:
Private Sub Button1_Click()
You could then call it with:
Call Form_Sub1.Button1_Click
or possibly with:
Call Sub1.Form.Button1_Click

Of course, it will depend what these buttons are trying to do. If you have
an Undo button on the main form, this may not do what you expect for the
subform, due to the timing of the events. When you click the button on the
mainform, Access saves the record in the subform before it moves focus to
the button in the main form. So if your code tries to use the Undo method of
the form in the subform control, it's too late. For this kind of task, use
the toolbar buttons instead.
 
S

slagg7575

Thanks,

But it is just to have all my command buttons on the right side of the
main form. I have custom record selectors on the subform as well, and I
would like the user to use custom record selectors from the main form
that navigate the subform. Does that make sense? Right now, the only
way to navigate through the subform records is to have the command
buttons(next record, previuos record, etc) on the subform, and I want
them on the main form. Can this be done?
Thanks
 
A

Allen Browne

If the command button is on the main form, SetFocus to the subform control,
and then to a control within the subform, and then attempt the move. This
kind of thing:

Private Sub cmdNextInSubform_Click()
With Me.[Sub1]
.SetFocus
.Form![Ctl1].SetFocus
If .NewRecord Then
Beep
Else
RunCommand acCmdRecordsGoToNext
End If
End With
End Sub
 

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