• Public Function (A2K)

    Author
    Topic
    #444125

    Good Morning Everyone,

    My form has 21 controls on it. I’m currently using a lenghy Select Case to control the properties of each control. Each time a control is added/removed, I need to modify the Select Case Statement w/6 Cases.

    To simplify things, I thought it would more functional and less work if this code were in a module, rather than Private on the Form itself. I could use the TAG property to handle this (some controls.tag would be null) would be to my advantage. The following is code I’ve tried without success.

    [indent]


    Public Sub mmControls()
    Dim f As Form
    Dim C As Control

    Set f = Forms![Main Menu]
    For Each C In f
    If C.Tag = “Dev” Then
    C.Visible = True
    If C.Tag = “Exec; Dev” Then
    C.Visible = True
    End If
    If C.Tag = “Admin” Then
    C.Visible = True
    End If
    If C.Tag = “Dev; Exec; Admin” Then
    C.Visible = True
    End If

    ‘ For Each C In F
    ‘Find the Control Tag property to determnine permissions
    ‘4 Possiblities: Dev, ExecAdmin, Admin, and User
    ‘ If C.Tag = “Dev”
    ‘ C.Visible = True
    ‘ End If
    ‘ Next C

    ‘Set C = f.C.Tag
    ‘ Select Case C
    ‘ Case 1 ‘Dev
    ‘ C.Visible = True
    ‘ Case 2 ‘Exec; Dev
    ‘ C.Visible = True
    ‘ Case 3 ‘Admin
    ‘ C.Visible = True
    ‘ Case 4 ‘Dev; Exec; Admin
    ‘ C.Visible = True
    ‘ End Select
    Next C


    [/indent]

    The ‘ indicates code I’ve tried and didn’t work. If someone has a suggestion, I would love to here it.

    Thanks,

    Viewing 0 reply threads
    Author
    Replies
    • #1073159

      I don’t see any advantage in using a procedure in a standard module here, since the code is specific to a single form.
      You could use a loop like this:

      Dim C As Control
      For Each C In Me.Controls
      ‘ Does the tag contain Dev?
      If InStr(C.Tag, “Dev”) > 0 Then

      End If
      ‘ Does the tag contain Exec?
      If InStr(C.Tag, “Exec”) > 0 Then

      End If
      ‘ Does the tag contain Admin?
      If InStr(C.Tag, “Admin”) > 0 Then

      End If
      Next C

      • #1073161

        Actually HANS, this code will apply to several forms. I didn’t mention it in my post because I want to make sure I can achieve this before it’s applies to the other forms. My apologies, I didn’t realize it was important enough to mention.

        I’m getting a Compile Error: Invalid use of Me keyword and ….
        Can the me.controls be substitued with code to call the current form the user is on? That’s why I wad declaring f as form.

        • #1073166

          In the standard module, define the procedure like this:

          Public Sub mmControls(f As Form)
          Dim C As Control
          For Each C In f.Controls


          End Sub

          When calling the code from a form, use

          Call mmControls(Me)

          In the code behind a form, Me stands for the form itself. This is passed to the mmControls procedure.

      • #1073165

        Hans,

        I’ve got it working. I made the following changes….and as always, thank you.

        [indent]


        Dim F As Form

        Set F = Screen.ActiveForm
        Dim C As Control

        For Each C In F.Controls
        ‘ Does the tag contain Dev?
        If InStr(C.Tag, “Dev”) > 0 Then
        C.Visible = True
        End If
        ‘ Does the tag contain Exec?
        If InStr(C.Tag, “Exec”) > 0 Then
        C.Visible = True
        End If
        ‘ Does the tag contain Admin?
        If InStr(C.Tag, “Admin”) > 0 Then
        C.Visible = True
        End If
        Next C


        [/indent]

    Viewing 0 reply threads
    Reply To: Public Function (A2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: