Results' visibility tied to checkbox value?

KAyers

Registered User.
Local time
Today, 17:48
Joined
Oct 30, 2007
Messages
23
I have created a form with checkboxes controlling the enabling of certain groups of fields. Now that I am constructing the report, I have a subreport which should display a field from group 1 if checkbox 1=true if not it should show a field from group 3. I looked for something similar in the threads but my search words may be incorrect- sorry if this is a dup. My question is- should I use similar coding to the form's enable/disable for the report? I am not as familiar with reports so I don't know if this is the best way to go and I'm not sure how to tie this into the report without event handlers for the text field- perhaps I should be using the onFormat for the report detail- I'm not sure and I'm hitting a wall here!
Thanks for any help!
K

'Group Disable/Enable settings
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, acCommandButton
If fGetGroup(Ctl.Name, strGroup) Then Ctl.Enabled = False
End Select
Next Ctl
End Sub

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, acCommandButton
If fGetGroup(Ctl.Name, strGroup) Then Ctl.Enabled = True
End Select
Next Ctl
End Sub

'Unit 1 (Group 1 "G1") Disable/Enable by checkbox
Private Sub U1_AfterUpdate()
Call U1_Group
End Sub

Private Sub U1_Group()
If Nz(Me.U1) Then
Call fEnableGrp("G1")
Else
Call fDisableGrp("G1")
End If
End Sub
 
Last edited:
Update! my effort so far...

Here is where I have gotten so far. Unfortunately I need a bit more from the results. If a field (which is set to invisible) ends in "A" then U1 must be true so G1 would be visible. "B" can have either U1 or P1 as true (P1 trumps U1) so if P1 is true then G2 would be visible and G1 would be invisible. "C" can have U1, P1, or P2 (P1 trumps U1 but P2 trumps all) so if P2 is true then G3 would be visible and G1 and G2 would be invisible. I have tried to diagram this logic on a whiteboard to go over it with the coworker requesting this and our heads nearly popped! Should I be moving some of this off to another query or can this all be included in the code?

Private Sub Report_Current()
U1_Group
End Sub

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Call U1_Group
End Sub

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

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

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

Private Sub U1_Group()
If Nz(Me.U1) Then
Call fVisibleGrp("G1")
Else
Call fVisibleGrp("G2")
End If
End Sub
 
Another attempt!

OK... Instead of trying to build one giant report, I have broken the report into the 3 parts (A, B, and C) which simplifies things. Unfortunately, my attempts to separate out the visibility based on the checkbox results has not worked and they are displaying all- I do have the visibility set to no to begin with so I'm a little stumped and I think my code is getting ugly as I flail!

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Call P1_Group
Call P2_Group
Call U2_Group
End Sub

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

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

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

Private Sub P1_Group()
If Me.P1 = True Then
Call fVisibleGrp("G1")
Else
Call P2_Group
End If
End Sub

Private Sub P2_Group()
If Me.P2 = True Then
Call fVisibleGrp("G2")
Else
Call U2_Group
End If
End Sub

Private Sub U2_Group()
If Me.U2 = True Then
Call fVisibleGrp("G3")
End If
End Sub
 
Can anyone help me with this?!?!
 
KAyers

If you post you code within code tags [ Code ] and terminated with [ / code ] it makes it much easier to read and people might be tempted to help you.

Rob
 
Thanks for the tip- no one had mentioned that before. It's unfortunate if that is the reason no one had replied.
K

As for a solution for anyone interested I found a possible compromise. It seems to be working but if anyone finds a huge hole in the logic please let me know:

Code:
Option Compare Database

Private Sub Report_Current()
    P1_Group
    P2_Group
    U2_Group
End Sub

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
    Call P1_Group
End Sub

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

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

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

Private Sub P1_Group()
    If Me.P1 = True Then
    Call fVisibleGrp("G1")
    Call fInvisibleGrp("G2")
    Call fInvisibleGrp("G3")
    Else
    Call P2_Group
    End If
End Sub

Private Sub P2_Group()
    If Me.P2 = True Then
    Call fVisibleGrp("G2")
    Call fInvisibleGrp("G1")
    Call fInvisibleGrp("G3")
    Else
    Call U2_Group
    End If
End Sub

Private Sub U2_Group()
    If Me.U2 = True Then
    Call fVisibleGrp("G3")
    Call fInvisibleGrp("G1")
    Call fInvisibleGrp("G2")
    Else
    Call fInvisibleGrp("G3")
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom