Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trying to lock certain controls by calling function

Posted on 2016-11-14
7
Medium Priority
?
99 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 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
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's take a look into the basics of ransomware—how it spreads, how it can hurt us, and why a disaster recovery plan is important.
Phishing emails are a popular malware delivery vehicle for attack.  While there are many ways for an attacker to increase the chances of success for their phishing emails, one of the most effective methods involves spoofing the message to appear to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

963 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