Wrestling with enabling/disabling in a hand-me-down form (1 Viewer)

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
Hello!

I have inherited a form that promised much but was short on delivery. At present I have checkboxes controlling combo boxes and buttons for 7 distinct sections of a form. Ultimately, upon creation of a new record, I would like to have the user see disabled boxes and buttons for all sections until they check the section 1 box. All other sections remain disabled until they too are checked- in any order they are checked, so they could enable section 1, 5, and then 3. Currently, all fields are disabled with the new record but once one checkbox is selected all of the fields are enabled, including those on new records. I have been doing a lot of research but most suggestions don't address multiple disabled sections or resetting for new records. I'm not sure where the original creator was coming from so I didn't want to monkey blindly. I'm sorry this is so long- any help would be greatly appreciated. Here is the original set up:

Private Sub Active1()
Dim Ex As Boolean
Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next ctrl

If Not Me!U1 Or Ex Then
Ex = True
Me.Unit1.Enabled = False
Me.Unit1Jack.Enabled = False
Me.AddUnit1.Enabled = False
End If

End Sub
Private Sub Active2()
Dim Ex As Boolean
Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next ctrl

If Not Me!A Or Ex Then
Ex = True
Me.ConnectorAX.Enabled = False
Me.AddConnector1.Enabled = False
Me.BackshellAX.Enabled = False
Me.AddBackshell1.Enabled = False
Me.CableTypeA.Enabled = False
Me.AddCable1.Enabled = False
Me.CableALength.Enabled = False
Me.ConnectorAY.Enabled = False
Me.AddConnector2.Enabled = False
Me.BackshellAY.Enabled = False
Me.AddBackshell2.Enabled = False
End If

End Sub

Private Sub Active3()
Dim Ex As Boolean
Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next ctrl

If Not Me!P1 Or Ex Then
Ex = True
Me.Plate1.Enabled = False
Me.AddPlate1.Enabled = False
Me.Plate1Receptacle.Enabled = False
Me.Plate1Jack.Enabled = False
End If

End Sub

Private Sub Active4()
Dim Ex As Boolean
Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next ctrl

If Not Me!B Or Ex Then
Ex = True
Me.ConnectorBX.Enabled = False
Me.AddConnector3.Enabled = False
Me.BackshellBX.Enabled = False
Me.AddBackshell3.Enabled = False
Me.EMICategoryB.Enabled = False
Me.AddEMICategory1.Enabled = False
Me.CableTypeB.Enabled = False
Me.AddCable2.Enabled = False
Me.CableBLength.Enabled = False
Me.ConnectorBY.Enabled = False
Me.AddConnector4.Enabled = False
Me.BackshellBY.Enabled = False
Me.AddBackshell4.Enabled = False
End If

End Sub

Private Sub Active5()
Dim Ex As Boolean
Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next ctrl

If Not Me!P2 Or Ex Then
Ex = True
Me.Plate2.Enabled = False
Me.AddPlate2.Enabled = False
Me.Plate2Receptacle.Enabled = False
Me.Plate2Jack.Enabled = False
End If

End Sub

Private Sub Active6()
Dim Ex As Boolean
Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next ctrl

If Not Me!C Or Ex Then
Me.ConnectorCX.Enabled = False
Me.AddConnector5.Enabled = False
Me.BackshellCX.Enabled = False
Me.AddBackshell5.Enabled = False
Me.CableTypeC.Enabled = False
Me.AddCable3.Enabled = False
Me.CableCLength.Enabled = False
Me.ConnectorCY.Enabled = False
Me.AddConnector6.Enabled = False
Me.BackshellCY.Enabled = False
Me.AddBackshell6.Enabled = False
End If

End Sub

Private Sub Active7()
Dim Ex As Boolean
Dim ctrl As Control

On Error Resume Next
For Each ctrl In Me.Controls
ctrl.Enabled = True
Next ctrl

If Not Me!U2 Or Ex Then
Ex = True
Me.Unit2.Enabled = False
Me.Unit2Jack.Enabled = False
Me.AddUnit2.Enabled = False
End If

End Sub

Private Sub U1_AfterUpdate()
Active1
End Sub

Private Sub A_AfterUpdate()
Active2
End Sub

Private Sub P1_AfterUpdate()
Active3
End Sub

Private Sub B_AfterUpdate()
Active4
End Sub

Private Sub P2_AfterUpdate()
Active5
End Sub

Private Sub C_AfterUpdate()
Active6
End Sub

Private Sub U2_AfterUpdate()
Active7
End Sub
 

RuralGuy

AWF VIP
Local time
Today, 12:00
Joined
Jul 2, 2005
Messages
13,826
I can see code that serves no useful purpose but it is not easy for me to understand what you are trying to accomplish. Maybe if you could post your db so we could get a look at this form??
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:00
Joined
Jul 9, 2003
Messages
16,336
fLockAll - fUnlockAll

I would suggest you have a look at this thread here, it provides the ability to lock or unlock a group of controls.

What you could do is include a "code" in the name of each control in each group, for example group one controls could be called txtg1Name, you would then need to modify the code in the above link two extract the g1 or g2 portion of the control name and take action accordingly.
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
I'm sorry if my explanation is confusing. Thank you in advance for any help, I can't get the zip file size small enough to upload.
Would screenshots help?
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
Thank you- this looks promising. So you're thinking if I change the code to identify the group I can pick and choose which to enable. Unfortunately I'm not completely comfortable with this code yet so I'm not sure how I would identify the group. Instead of c.Name and then c.Locked would I be identifying them by say c.g1.Locked?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:00
Joined
Jul 9, 2003
Messages
16,336
fLock - fUnlock Example

On reflection the code I directed you to was a bit old fashioned, I have done an example which is attached.
 

Attachments

  • LockUnlockControls.zip
    21.3 KB · Views: 177

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
Thanks so much- the example is very straight forward! I'll apply it to the db on thursday and let you know how I faired... fingers crossed I don't foul it up.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:00
Joined
Jul 9, 2003
Messages
16,336
Progression in Code Development

I have made further improvements to the code, part of a blog I am doing.

The problem is if you need to add a significant number of command buttons, I would imagine five or more then you are going to get a lumpy looking code module with lots of repeating code in it.

I was reasonably sure that the command button could be made to activate a class module, I did a bit of research and came up with these four forms showing a progression in code development.
 

Attachments

  • LockUnlockControls.zip
    41.5 KB · Views: 166

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
Thank you for all of the help! I have adapted one of the two button versions of your work from the latest db you shared:

Private Sub fDisableGrp(strGroup As String)
Dim Ctl As Control
For Each Ctl In Me.Controls
Select Case Ctl.ControlType
Case acTextBox, acComboBox, acOptionGroup, acListBox
If fGetGroup(Ctl.Name, strGroup) Then Ctl.Enabled = False
End Select
Next Ctl
End Sub 'fLockGrp

Private Sub fEnableGrp(strGroup As String)
Dim Ctl As Control
For Each Ctl In Me.Controls
Select Case Ctl.ControlType
Case acTextBox, acComboBox, acOptionGroup, acListBox
If fGetGroup(Ctl.Name, strGroup) Then Ctl.Enabled = True
End Select
Next Ctl
End Sub 'fUnLockGrp

Private Function fGetGroup(strCtrlName As String, strGroup As String) As Boolean
Dim str1 As String
str1 = Mid(strCtrlName, 1, 2)
fGetGroup = False
If str1 = strGroup Then fGetGroup = True
End Function 'fGetGroup

Private Sub G1Disable_Click()
On Error GoTo Err_G1Disable_Click

Call fDisableGrp("G1")

Exit_G1Disable_Click:
Exit Sub

Err_G1Disable_Click:
MsgBox Err.Description
Resume Exit_G1Disable_Click
End Sub 'btnLockG1_Click

Private Sub G1Enable_Click()
On Error GoTo Err_G1Enable_Click

Call fEnableGrp("G1")

Exit_G1Enable_Click:
Exit Sub

Err_G1Enable_Click:
MsgBox Err.Description
Resume Exit_G1Enable_Click
End Sub 'btnUnlockG1_Click

Private Sub G2Disable_Click()
On Error GoTo Err_G2Disable_Click

Call fDisableGrp("G2")

Exit_G2Disable_Click:
Exit Sub

Err_G2Disable_Click:
MsgBox Err.Description
Resume Exit_G2Disable_Click
End Sub 'btnLockG1_Click

Private Sub G2Enable_Click()
On Error GoTo Err_G2Enable_Click

Call fEnableGrp("G2")

Exit_G2Enable_Click:
Exit Sub

Err_G2Enable_Click:
MsgBox Err.Description
Resume Exit_G2Enable_Click
End Sub 'btnUnlockG1_Click

Private Sub G3Disable_Click()
On Error GoTo Err_G3Disable_Click

Call fDisableGrp("G3")

Exit_G3Disable_Click:
Exit Sub

Err_G3Disable_Click:
MsgBox Err.Description
Resume Exit_G3Disable_Click
End Sub 'btnLockG1_Click

Private Sub G3Enable_Click()
On Error GoTo Err_G3Enable_Click

Call fEnableGrp("G3")

Exit_G3Enable_Click:
Exit Sub

Err_G3Enable_Click:
MsgBox Err.Description
Resume Exit_G3Enable_Click
End Sub 'btnUnlockG1_Click

Private Sub G4Disable_Click()
On Error GoTo Err_G4Disable_Click

Call fDisableGrp("G4")

Exit_G4Disable_Click:
Exit Sub

Err_G4Disable_Click:
MsgBox Err.Description
Resume Exit_G4Disable_Click
End Sub 'btnLockG1_Click

Private Sub G4Enable_Click()
On Error GoTo Err_G4Enable_Click

Call fEnableGrp("G4")

Exit_G4Enable_Click:
Exit Sub

Err_G4Enable_Click:
MsgBox Err.Description
Resume Exit_G4Enable_Click
End Sub 'btnUnlockG1_Click

Private Sub G5Disable_Click()
On Error GoTo Err_G5Disable_Click

Call fDisableGrp("G5")

Exit_G5Disable_Click:
Exit Sub

Err_G5Disable_Click:
MsgBox Err.Description
Resume Exit_G5Disable_Click
End Sub 'btnLockG1_Click

Private Sub G5Enable_Click()
On Error GoTo Err_G5Enable_Click

Call fEnableGrp("G5")

Exit_G5Enable_Click:
Exit Sub

Err_G5Enable_Click:
MsgBox Err.Description
Resume Exit_G5Enable_Click
End Sub 'btnUnlockG1_Click

Private Sub G6Disable_Click()
On Error GoTo Err_G6Disable_Click

Call fDisableGrp("G6")

Exit_G6Disable_Click:
Exit Sub

Err_G6Disable_Click:
MsgBox Err.Description
Resume Exit_G6Disable_Click
End Sub 'btnLockG1_Click

Private Sub G6Enable_Click()
On Error GoTo Err_G6Enable_Click

Call fEnableGrp("G6")

Exit_G6Enable_Click:
Exit Sub

Err_G6Enable_Click:
MsgBox Err.Description
Resume Exit_G6Enable_Click
End Sub 'btnUnlockG1_Click

Private Sub G7Disable_Click()
On Error GoTo Err_G7Disable_Click

Call fDisableGrp("G7")

Exit_G7Disable_Click:
Exit Sub

Err_G7Disable_Click:
MsgBox Err.Description
Resume Exit_G7Disable_Click
End Sub 'btnLockG1_Click

Private Sub G7Enable_Click()
On Error GoTo Err_G7Enable_Click

Call fEnableGrp("G7")

Exit_G7Enable_Click:
Exit Sub

Err_G7Enable_Click:
MsgBox Err.Description
Resume Exit_G7Enable_Click
End Sub 'btnUnlockG1_Click
'Thanks to UncleGizmo on access-programmers.co.uk

This seems to have done the trick! It is far more straight forward than what I was dealing with previously. True there are many buttons but on the form it is visually simple for the user.
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
New issue cropped up!

From the code I published in my last reply I'm getting a problem with the enable/disable event for the groups in my form. In the form design, all of the groups are set to Enable "no" but whatever button I select for a particular group is then applied to all other records in the table. How do I make the enable/disable selection a unique setting for each record?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:00
Joined
Jul 9, 2003
Messages
16,336
Seven explanatory Videos available.

I have finished my Blog (a series of seven Videos) based on the Lock/Unlock code in this thread. There is also a new demo database with five forms in it showing how the code progresses from directly changing other controls properties, to a method which employs a class module to change a group of similar controls, in this case a set of command buttons.

The Blog (Videos) available here:
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:00
Joined
Jul 9, 2003
Messages
16,336
>>>>How do I make the enable/disable selection a unique setting for each record?<<<<

Try putting a message box in the following code where indicated, just make sure you are actually inspecting the right part of your control name.

Private Function fGetGroup(strCtrlName As String, strGroup As String) As Boolean
Dim str1 As String
str1 = Mid(strCtrlName, 1, 2)
fGetGroup = False
MsgBox " >>> " & str1
If str1 = strGroup Then fGetGroup = True
End Function 'fGetGroup
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
I'm not sure I follow- the message box will ensure that when I enable groups (ex: 3, 4 and 6 for record #245) that all new records won't share the same setting? I want every new record to start with a "clean slate" with all groups disabled while preserving the enabled status of the previous records- they should all have the capacity to be different.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 19:00
Joined
Jul 9, 2003
Messages
16,336
>>> unique setting for each record?<<<

When you said record, I assumed you meant a text box on the form displaying some information. Now I am thinking that you really meant an actual record, when you move from one record to another in the form? Could you please Make this Distinction?
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
Sorry for the long delay- we had a big storm come through and take out the lines for the cable.
I'm sorry I hadn't been more explicit- yes, I meant an actual record as you move through the form so that record #3 has no impact on the selections for record #27 and so on. We are trying to put together a very large materials list with diagrams that correspond to certain configurations... the disable/enable controls which configurations are chosen and thus narrows the choices of materials available. This must be able to change for each record.
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
Sorry to continue this but can anyone help me keep every group setting (disabled/enabled) separate for each record as someone enters data into the form? The greyed out boxes should be an a la carte menu for the user to make different configurations for each record so that every row on the associated table could have a different set of groups enabled without affecting down or upstream rows- which would be a visually different arrangement for each record as the user scrolls through the form.
 

RuralGuy

AWF VIP
Local time
Today, 12:00
Joined
Jul 2, 2005
Messages
13,826
I have not been following this thread very closely because it seemed that you were making headway with Tony's examples. In order for each record to have unique groups of controls enabled/disabled, each record will need this information encoded in the record. What field will you use to save the user's selection on each record?
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
Modifications have been made!

Thanks for any help- I feel like progress is painfully slow with this issue. I have done away with the buttons and tied them to checkboxes recording true/false in the associated table. The only issue now is that it seems to call ALL group 1 (G1) in the form if the "A" checkbox is updated in recordset #37 regardless of the fact that the t/f update was for record #37 only, for example. Update:

Private Sub fDisableGrp(strGroup As String)
Dim Ctl As Control
For Each Ctl In Me.Controls
Select Case Ctl.ControlType
Case acTextBox, acComboBox, acOptionGroup, acListBox
If fGetGroup(Ctl.Name, strGroup) Then Ctl.Enabled = False
End Select
Next Ctl
End Sub 'fLockGrp

Private Sub fEnableGrp(strGroup As String)
Dim Ctl As Control
For Each Ctl In Me.Controls
Select Case Ctl.ControlType
Case acTextBox, acComboBox, acOptionGroup, acListBox
If fGetGroup(Ctl.Name, strGroup) Then Ctl.Enabled = True
End Select
Next Ctl
End Sub 'fUnLockGrp

Private Function fGetGroup(strCtrlName As String, strGroup As String) As Boolean
Dim str1 As String
str1 = Mid(strCtrlName, 1, 2)
fGetGroup = False
If str1 = strGroup Then fGetGroup = True
End Function 'fGetGroup

Private Sub U1_AfterUpdate()
If Me.U1 Then
Call fEnableGrp("G1")
Else
Call fDisableGrp("G1")
End If
End Sub

Private Sub A_AfterUpdate()
If Me.A Then
Call fEnableGrp("G2")
Else
Call fDisableGrp("G2")
End If
End Sub

Private Sub P1_AfterUpdate()
If Me.P1 Then
Call fEnableGrp("G3")
Else
Call fDisableGrp("G3")
End If
End Sub

Private Sub B_AfterUpdate()
If Me.B Then
Call fEnableGrp("G4")
Else
Call fDisableGrp("G4")
End If
End Sub

Private Sub P2_AfterUpdate()
If Me.P2 Then
Call fEnableGrp("G5")
Else
Call fDisableGrp("G5")
End If
End Sub

Private Sub C_AfterUpdate()
If Me.C Then
Call fEnableGrp("G6")
Else
Call fDisableGrp("G6")
End If
End Sub

Private Sub U2_AfterUpdate()
If Me.U2 Then
Call fEnableGrp("G7")
Else
Call fDisableGrp("G7")
End If
End Sub
 

RuralGuy

AWF VIP
Local time
Today, 12:00
Joined
Jul 2, 2005
Messages
13,826
I have not studied the code enough to completely understand what it is doing but you *will* need some sort of code in the Current event of the form to impliment unique controls for each record. You get a Current event each time you move to a new record.
 

KAyers

Registered User.
Local time
Today, 14:00
Joined
Oct 30, 2007
Messages
23
AHHHHHHHHHH! Thank you for the fresh eyes! I kept going over the code but I hadn't updated it to include the new buttons or checkboxes that replaced them- I've been looking at it for so long I was blind it!

Thank you, thank you!
The finished element:

Private Sub Form_Current()
U1_AfterUpdate
A_AfterUpdate
P1_AfterUpdate
B_AfterUpdate
P2_AfterUpdate
C_AfterUpdate
U2_AfterUpdate
Inactive_AfterUpdate
End Sub
 

Users who are viewing this thread

Top Bottom