Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trying to lock certain controls by calling function

Posted on 2016-11-14
7
Medium Priority
?
92 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 2000 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
When ransomware hits your clients, what do you do?

MSPs: Endpoint security isn’t enough to prevent ransomware.
As the impact and severity of crypto ransomware attacks has grown, Webroot fought back, not just by building a next-gen endpoint solution capable of preventing ransomware attacks but also by being a thought leader.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
A new hacking trick has emerged leveraging your own helpdesk or support ticketing tools as an easy way to distribute malware.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

664 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