471,355 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

enable one subform but not the other

AccessIdiot
493 256MB
I was successful with help from another thread (this one ) in enabling and disabling a form/subform with a button. Essentially you press a button on the form and the form controls are disabled but the subform is enabled. Then there is a button on the subform that re-enables the form controls and disables the subform.

This works wonderfully but now I've got two subforms. I need the new subform to disable when the form controls are disabled and enable when the form controls are enabled. But I'm not sure how to refer to one subform.

Here is the code on the form that disables form controls and enables the subform:
Private Sub btnNewReplicate_Click()
Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType = acSubform Or ctl.Name = "btnNewReplicate" Then
ctl.Enabled = True
Else
If ctl.ControlType <> acLabel Then
ctl.Enabled = False
End If
End If
Next
End Sub[/code]

And here is the code on the subform that enables the form controls and disables the subform:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnNewSurvey_Click()                                                    'New Survey button - enable form, disable subform
  2. Dim ctl As Control
  3. For Each ctl In Me.Parent.Controls
  4.     If ctl.ControlType <> acLabel And Not ctl.ControlType = acSubform Then
  5.         ctl.Enabled = True
  6.         ctl.SetFocus
  7.    ElseIf ctl.ControlType = acSubform Then
  8.         ctl.Enabled = False
  9.     End If
  10. Next
  11.  
  12. DoCmd.GoToRecord acDataForm, "frm_Survey", acNewRec
  13. DoCmd.GoToControl "txt_SurveyNum"
  14.  
  15.  
  16. End Sub
It's this line that is messing me up:
Expand|Select|Wrap|Line Numbers
  1. If ctl.ControlType = acSubform
because I'm not sure how to refer to one subform and not the other. I'm guessing I need to say something like "if control type = subform AND subform name = the one I want then enabled = true or false". But I have no idea how to target a specific subform in this case. Can I use ctl.Name to reference a subform?
Mar 29 '07 #1
3 2541
Rabbit
12,516 Expert Mod 8TB
I was successful with help from another thread (this one ) in enabling and disabling a form/subform with a button. Essentially you press a button on the form and the form controls are disabled but the subform is enabled. Then there is a button on the subform that re-enables the form controls and disables the subform.

This works wonderfully but now I've got two subforms. I need the new subform to disable when the form controls are disabled and enable when the form controls are enabled. But I'm not sure how to refer to one subform.

Here is the code on the form that disables form controls and enables the subform:
Private Sub btnNewReplicate_Click()
Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType = acSubform Or ctl.Name = "btnNewReplicate" Then
ctl.Enabled = True
Else
If ctl.ControlType <> acLabel Then
ctl.Enabled = False
End If
End If
Next
End Sub[/code]

And here is the code on the subform that enables the form controls and disables the subform:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnNewSurvey_Click()                                                    'New Survey button - enable form, disable subform
  2. Dim ctl As Control
  3. For Each ctl In Me.Parent.Controls
  4.     If ctl.ControlType <> acLabel And Not ctl.ControlType = acSubform Then
  5.         ctl.Enabled = True
  6.         ctl.SetFocus
  7.    ElseIf ctl.ControlType = acSubform Then
  8.         ctl.Enabled = False
  9.     End If
  10. Next
  11.  
  12. DoCmd.GoToRecord acDataForm, "frm_Survey", acNewRec
  13. DoCmd.GoToControl "txt_SurveyNum"
  14.  
  15.  
  16. End Sub
It's this line that is messing me up:
Expand|Select|Wrap|Line Numbers
  1. If ctl.ControlType = acSubform
because I'm not sure how to refer to one subform and not the other. I'm guessing I need to say something like "if control type = subform AND subform name = the one I want then enabled = true or false". But I have no idea how to target a specific subform in this case. Can I use ctl.Name to reference a subform?
Absolutely. You can use If ctl.Name = "Text" instead of the Type.
Mar 29 '07 #2
AccessIdiot
493 256MB
Of course! Now why didn't I think of that?!

Thanks! :D
Mar 29 '07 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem.
Mar 29 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

14 posts views Thread by Kurt | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.