By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,524 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Call Function On Main Form to Sub Form

P: n/a
I have a form (frmAppointment) with a subform on it
(frmAppointmentsub1). I have placed a command button on the main form
which calls the function below from the module. The purpose of this
function is to make fields beginning with YY invisble OnClick of the
command button on the main form. It works for the fields on the main
form but not on the subform. What do I need to add or do to make it
work on the subform? Any help would be most appreciated.

Thank You
TD

The command button on the main form event procedure is:

Private Sub cmdYY_Click()

Dim I As Integer
I = glrInvisbleFields(Me)

End Sub
The module function is:

Function glrInvisbleFields(F As Form)

Dim I As Integer
Dim C As Control
Dim X As Variant

For I = 0 To F.Count - 1
Set C = F(I)

If Left$(C.Name, 2) = "YY" Then
C.Visible = False

End If
Next I
End Function
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
this code may help (it assumes that the name of the subform does not start
with YY, I have not tested it, but it may work....

Any questions, please ask

Function glrInvisbleFields(F As Form)

Dim I As Integer
Dim C As Control
Dim X As Variant
Dim Fsub as form
Dim Csub as control
'----------------------------------------------------
For each C in F
If Left$(C.Name, 2) = "YY" Then
C.Visible = False
else
Csub.visible = true
If F.DefaultView = 0 Then 'single form
If F.ActiveControl.ControlType = acSubform Then
Set Fsub = Screen.ActiveForm.ActiveControl.Form

for each Csub in Fsub
if Left$(Csub.Name, 2) = "YY" Then
Csub.Visible = False
else
Csub.visible = true
end if
next Csub
End If
End If
End If
Next I
End Function
Nov 13 '05 #2

P: n/a
Thanks for your response. I have tried your suggeston and now get the
error message when compiling:

Compile Error
Invalid Next Control Variable Reference

With the Debuging Highlighting the: "Next I" portion of the code.

Suggestions

Thanks again for your response.
TD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

P: n/a
Tom, Change it to Next C

--
Reggie

----------
"Tom Dean" <td****@hotmail.com> wrote in message
news:40**********************@news.newsgroups.ws.. .
Thanks for your response. I have tried your suggeston and now get the
error message when compiling:

Compile Error
Invalid Next Control Variable Reference

With the Debuging Highlighting the: "Next I" portion of the code.

Suggestions

Thanks again for your response.
TD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.