Solved Getting Permissions form worked by control multiple controls by Tags (1 Viewer)

alvingenius

IT Specialist
Local time
Today, 13:54
Joined
Jul 10, 2016
Messages
169
Hello,

This Post is following this post to know how to control a group of controls

I have a users table with permissions of accessing forms/reports
and in this table 2 more checkboxes as rules Manger / Custom ( later maybe i convert it to combo box )

Manager have access to everything / custom have to set what to access

in permission form i've set record source to a query for this table and i've set a combo box to get user names from users qry
and listed all controls by users query

and all controls disabled by default except users combo box

attachment.php


in combo box of users "after update" event i've set this code

Code:
EnableControls True, "sec1"

to enable this section( Sec1 is tag for manager/custom controls )

then in Manager ON Click event i want all controls of checkboxes to be True

Code:
Private Sub optManager_Click()
Dim ctrl As Control
    If Me.optManager = True Then
        For Each ctrl In Me.Controls
        If ctrl.Tag = "secMain" Or ctrl.Tag = "secForm" Or ctrl.Tag = "secReport" Then [COLOR="green"]' all control tags[/COLOR]
            ctrl = True [COLOR="green"]' check all controls[/COLOR]
            ctrl.Enabled = False [COLOR="Green"]' can't edit controls anymore[/COLOR]
            Me.optCustom = False [COLOR="Green"]' remove check from other checkbox[/COLOR]
        End If
        Next ctrl
    End If
End Sub

Tags is shown in screenshot attached

now , when i open form and choose user Rules section (Sec1) shown up and when click on Manager i'm getting error

attachment.php


my idea is
when to check manager then all controls in tags secMain, secForm and secReport = True and all this controls Disabled
and if unchecked it by clicking on Custom then all tag controls Enabled to choose whatever i want .

what i'm doing wrong here !:confused::banghead:
 

Attachments

  • per.PNG
    per.PNG
    21.8 KB · Views: 557
  • perm2.PNG
    perm2.PNG
    7.6 KB · Views: 387
Last edited:
Sounds like you have tagged a label.?
They cannot be enabled I believe.?

If you click the debug button you can find out for definite as to which control is causing the problem?
 
Sounds like you have tagged a label.?
They cannot be enabled I believe.?

no this label is only to show it to u
attachment.php
 

Attachments

  • perm3.PNG
    perm3.PNG
    19.9 KB · Views: 359
? ctrl.name in the Immediate Window of the debugger and see what the ctrl is.?

or put Debug.Print ctrl.name before that line highlighted and view the immediate window.

From your previous pic, it looked like the labels for the options have tags completed?

FYI I am not helping via PMs, as this might help others in the future.
 
Last edited:
? ctrl.name
Label681

this label for "Open Master File " but why it's refer there ?
 
I'm with Gasman on the idea that you might have inadvertantly tagged something that should not have been tagged.

In the apps where I do a For Each x In Me.Controls type of loop, I always add a test inside the loop for Me.Type = acCommandButton (or acTextBox, or whatever type of control I was looking to change). The error you have named is actually quite common for loops that scan all controls. Makes it a pain in the toches, but if you make a subroutine out of it, you might only have to write it once and then just call it when you need it.

This also happens a lot when diddling with the .Value of something because some controls don't have a value. Labels and lines, e.g., have no value. Neither to Option Buttons. (There, the option GROUP has the value.)
 
You went and selected a bunch of controls with the mouse and half of those are labels for options?

Labels cannot be enabled as I suspected.

I do not think you need to test the type of control (which is normally done when looping through the collection) as long as you tag the correct controls. You haven't at present.
 
Ooh

i've selected all controls in layout and it included labels on this controls and that's why error occurred

to fix it i've edited all labels tags to a different name and it work now

Thanks
 
? ctrl.name
FYI I am not helping via PMs, as this might help others in the future.

i did PM because i don't understand what u typed

and i don't wanna make the post tall !!

then u edited the post

Thanks anyways
icon14.gif
 
to fix it i've edited all labels tags to a different name and it work now

So, this is SOLVED now?
 
Re:- runtime error 438 - Object doesn't support this property or method

This problem often occurs when you run this type of loop because you are examining the properties of a control. However not all controls have the same properties. If you open a property sheet for a textbox and look under the data tab there are a number of properties including "Enabled" & "Locked".. However if you open a property sheet for a label and look under the data tab you will see that there are no properties listed. In other words a "Label" does not have the properties"Enabled" & "Locked". If you try and access a property that does not exist for any particular control then you will generate an error and your code will cease to run.

A Technique I often use, is to exclude certain types of controls from the For Next Loop. This technique prevents the code from attempting to examine an object that does not have the properties you are testing. To do this you add an extra step to your loop, a step that tests for the type of control. If the control is a label, commonly a type of control that serves no purpose from a coding point of view, you can exclude Label Controls from any further processing.

Code Snippet 1 below, examines the control type in the Select Case Statement, you can easily add or remove different types of control from your test routine by un-commenting the particular control type from the commented out part of the Select Case Statement...

This code is designed to remove the commonly used naming convention, a three digit prefix from the control name, then check to see if what's left constitutes a "duplicate name". For example if you had a combobox named:- cboDate and you had a text box named:- txtDate then the code would return:- "Date in the variable:- "strFoundControlName". This is a handy piece of code if you want to associate two controls together via the Controls' Names.

Code:
'Code Snippet 1
Dim strFoundControlName As String
Dim strNamePart As String

Dim Ctrl As Control
Dim X As Integer

    For Each Ctrl In Me.Controls
        Select Case Ctrl.ControlType
            Case acComboBox ,acTextBox ', acListBox, acOptionButton, acOptionGroup, acToggleButton, acLabel, acCheckBox
            If Right(Ctrl.Name, Len(Ctrl.Name) - 3) = strNamePart Then
                X = X + 1
                strFoundControlName = Ctrl.Name
            End If
        End Select
    Next Ctrl

Code Snippet 2 below, uses "TypeOf" in an IF Statement instead of "Ctrl.ControlType" as demonstrated above. This example only selects one particular type of control and in this case will only check the checkboxes on your form:-

Code:
'Code Snippet 2
Dim Ctrl As Control

    For Each Ctrl In Me.Controls
        If TypeOf Ctrl Is CheckBox Then
            If Ctrl = False Then Form_frmQC.sFrmWinTblFaults.Visible = True
        End If
    Next Ctrl
 
Last edited:
I would agree with that wholeheartedly Tony for most occasions, but in this case if the correct controls were tagged with the correct data, there would be no need to inspect the type of control in this case.?
 
My apologies Paul, and other contributors, I should have pointed out, I'm not criticising any answers given, I think the thread has been answered very well. I'm just adding some extra information and alternatives...
 
Tony,
I did not consider it as a criticism, I doubt the other responders did either, as that good practice was mentioned previously.
 
Either way works. As it happened, I used tags for enabling and disabling controls by role, but I had such a thing as a form "state" (not related to any state declared by Access). I would define the visual formats of controls that had values based on the form having been opened as "ReadOnly" or "Normal" or "Dirty" or whatever other states cropped up. (I recall five states in total.) For things that were visible, I would change borders, backgrounds, and foregrounds based on whether the control was virgin, dirty, read-only, out-of-bounds, or normal (meaning you had tabbed through it without changing it).
 
Last edited:
When setting up security, it is better to normalize the data rather than to use individual controls. That way as you add new objects, you only have to add them to the table, you never have to modify your forms or code.
 
This might give you a better idea of what I'm up to! I've put a blog about it on Nifty Access Here:- Run-time error 438 --- There's a couple of images showing the property differences between a text box and a label. I've duplicated the code from this thread, however it's a little clearer because it's in colour...
 

Users who are viewing this thread

Back
Top Bottom