473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 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 2631
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

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

Similar topics

25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
12
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course,...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
14
by: Kurt | last post by:
I have an unbound main form with an unbound subform. frmProjects fsubProjectList Using combo boxes, the user can select several search criteria on frmProjects and then click a command button....
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
26
AccessIdiot
by: AccessIdiot | last post by:
I have been looking through posts on events happening based on a combo box choice but none really get at the heart of what I am trying to do. I think this is simple but I'm a newbie so any hand...
51
AccessIdiot
by: AccessIdiot | last post by:
Hi there, I would like to put a button on my form that enables or unlocks the subform and at the same time disables (locks) the main form until the user is done with the subform. At that point the...
2
by: Rex | last post by:
I have a main form and a subform. The main form has a combo box control and the subform has a textfield. What I want to do is when the main form loads it should check the value of the combo box...
5
by: samdev | last post by:
I have created two combo boxes in a subform.... For example 1. Combo Box State 2. Combo Box City 3. When a state from the Combo Box State is selected, the City combo box updates to reflect...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.