473,569 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enable one subform but not the other

AccessIdiot
493 Contributor
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 = "btnNewReplicat e" 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 2645
Rabbit
12,516 Recognized Expert Moderator MVP
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 = "btnNewReplicat e" 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 Contributor
Of course! Now why didn't I think of that?!

Thanks! :D
Mar 29 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem.
Mar 29 '07 #4

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

Similar topics

25
10183
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 data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab...
12
18996
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, frmBrowseNegsSubform. I would like to perform an ascending or descending sort on any of the 7 columns shown in datasheet view in the subform control. I've...
4
6985
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 user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which...
14
11451
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. The command button passes the criteria as a string to a query. A subform, which is based on this query, shows the results of the search.
9
9674
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 master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
26
5664
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 holding and non-startling movements will help here. :-) I have a form Specimen with a dropdown that displays Species by Species_Code. In the Species...
51
15255
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 user would click a button on the subform that returns to the main form and re-disables the subform. In other words, enter data on the main form,...
2
2004
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 and if it, lets say "MZ" then the textfield in the subform must be enabled otherwise it should be remain disabled. This should be done without...
5
4889
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 the State chosen by only showing cities in that selected state. 4. When I open just the subform it works just fine but when I open the
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.