Solved

Trying to lock certain controls by calling function

Posted on 2016-11-14
7
40 Views
Last Modified: 2016-11-14
In the oncurrent event of a form I am trying to lock certain controls depending on the users security level while leaving others unlocked.

I have this in the oncurrent event:

Private Sub Form_Current()
    DisableControls
End Sub

Open in new window

and this in a private sub:

Private Sub DisableControls()
On Error GoTo Err_DisableControls

    If DLookup("[SecurityLevel]", "LOCALtblCurrentUser") > 2 Then

        Dim ctl As Control

        For Each ctl In Me.Controls

            Select Case ctl.ControlType
                Case acComboBox
                    If ctl.Name <> "cboFindRecord" Or ctl.Name <> "cboPartN" Then ctl.Locked = True
                Case acCommandButton
                    If ctl.Name <> "cmdMainMenu" Or ctl.Name <> "cmdGridView" Then ctl.Locked = True
                Case acTextBox
                    If ctl.Name <> "txtCompanyID" Then ctl.Locked = True
            End Select

        Next

    End If

Exit_DisableControls:
    Exit Sub

Err_DisableControls:
    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
    Resume Exit_DisableControls

End Sub

But when the form opens I get an error...

Error #438.  Object doesn't support this property or method.

Open in new window

0
Comment
Question by:SteveL13
  • 4
  • 3
7 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 41886443
try this revision


Dim ctl As Control
        For Each ctl In Me.Controls

            Select Case ctl.ControlType
                Case acComboBox
                    If ctl.Name = "cboFindRecord" Or ctl.Name = "cboPartN" Then
                    ctl.Locked = False
                    Else
                    ctl.Locked = True
                    End If
                Case acCommandButton
                    If ctl.Name = "cmdMainMenu" Or ctl.Name = "cmdGridView" Then
                    ctl.Locked = False
                    Else
                    ctl.Locked = True
                    End If

                Case acTextBox
                    If ctl.Name = "txtCompanyID" Then
                    ctl.Locked = False
                    Else
                    ctl.Locked = True
                    End If
            End Select

        Next

Open in new window

0
 

Author Comment

by:SteveL13
ID: 41886470
Same error message.  All I did was add

If DLookup("[SecurityLevel]", "LOCALtblCurrentUser") > 2 Then

and end if at the end of the code.

And if I comment those 2 lines out I still get the error.
0
 

Author Comment

by:SteveL13
ID: 41886475
And it only give me an error if DLookup("[SecurityLevel]", "LOCALtblCurrentUser") > 2
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41886484
what are the fields in table "LOCALtblCurrentUser" ?

you need to add a criteria to your dlookup()

If DLookup("[SecurityLevel]", "LOCALtblCurrentUser","UserName = '" & user & "'") > 2 Then
0
 

Author Comment

by:SteveL13
ID: 41886498
I got it with:

    Dim ctl As Control
    
    If DLookup("[SecurityLevel]", "LOCALtblCurrentUser") = 3 Then
    
        For Each ctl In Me.Controls

            Select Case ctl.ControlType
                Case acComboBox
                    If ctl.Name = "cboFindRecord" Or ctl.Name = "cboPartN" Then
                    ctl.Locked = False
'                    Else
'                    ctl.Locked = True
                    End If
                Case acCommandButton
                    If ctl.Name = "cmdMainMenu" Or ctl.Name = "cmdGridView" Then
                    ctl.Enabled = True
                    Else
                    ctl.Enabled = False
                    End If
                Case acTextBox
                    If ctl.Name <> "txtCompanyID" Then
                    ctl.Locked = True
                    Else
                    ctl.Locked = False
                    End If
            End Select

        Next
        
    End If

Open in new window


It seems some control can be locked, other enabled perhaps?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41886501
oh yeah command buttons can not be locked, just enable/ disable.
0
 

Author Comment

by:SteveL13
ID: 41886503
You definitely led me in the right direction.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now