Wrestling with enabling/disabling in a hand-me-down form

That's great news! FYI, it is not a good programming practice to execute event code out of order. There could be behind the scenes code that is executed by Access of which you are not aware. Much better to have the Control Event call another subroutine and then you can also call that same subroutine whenever you want. I'm not saying that what you have done won't work as you expect. It is just a better practice to do it the other way and not start developing habbits that might bite you later on.
 
I'm all for good habits- can you give me a sample as explanation because I think I understand what you're saying but I don't want to do something outrageously complicated due to my own ignorance.
 
I just changed U1_AfterUpdate as an example. You should Call SubRoutines!
Code:
Option Compare Database
Option Explicit

Private Sub Form_Current()
   [COLOR="Red"]Call U1_Test[/COLOR]
[COLOR="SeaGreen"]'   U1_AfterUpdate         '-- instead of this one[/COLOR]
   A_AfterUpdate
   P1_AfterUpdate
   B_AfterUpdate
   P2_AfterUpdate
   C_AfterUpdate
   U2_AfterUpdate
   Inactive_AfterUpdate
End Sub

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()
   [COLOR="Red"]Call U1_Test[/COLOR]
End Sub

[COLOR="Red"]Private Sub U1_Test()
   If Me.U1 Then
      Call fEnableGrp("G1")
   Else
      Call fDisableGrp("G1")
   End If
End Sub[/COLOR]

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
 

Users who are viewing this thread

Back
Top Bottom