Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Public Function (A2K)

    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.

    <hr>
    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<hr>

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

    Thanks,
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Public Function (A2K)

    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

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Public Function (A2K)

    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.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  4. #4
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Public Function (A2K)

    Hans,

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

    <hr>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<hr>
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Public Function (A2K)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •