Solved

Trying to lock certain controls by calling function

Posted on 2016-11-14
7
81 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

710 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