If...then for cmd button enable/disable

Johnny Drama

In need of beer...
Local time
Yesterday, 19:54
Joined
Dec 12, 2008
Messages
211
Hello all,

I have a menu form that has several cmd buttons on it. The buttons are enabled/disabled depending on the users permission level. For the admin I want all buttons to be enabled, however it appears that VBA reads the first condition and then skips the rest. Below is the code:

If User.AccessID = 1 Then
Me.cmdAdmin.Enabled = True
Me.cmdIad1.Enabled = True
Me.cmdMgmt.Enabled = True
Else
Me.cmdAdmin.Enabled = False
Me.cmdIad1.Enabled = False
Me.cmdMgmt.Enabled = False
End If

If User.AccessID = 2 Then
Me.cmdIad1.Enabled = True
Else
Me.cmdIad1.Enabled = False
End If

If User.AccessID = 3 Then
Me.cmdMgmt.Enabled = True
Else
Me.cmdMgmt.Enabled = False
End If

Any thoughts on what I'm doing wrong? Am I using the wrong conditional statement?

Thanks
 
Use the select statement after setting them all to false, using the if else statement you keep changing the value from one user level to another. ie

if User.AccessID=1 then you change them all to true
but then because his is not User.AccessID=2 you then
disenabled Me.cmdIad1 etc

Code:
Me.cmdAdmin.Enabled = False
Me.cmdIad1.Enabled = False
Me.cmdMgmt.Enabled = False

Select Case User.AccessID

    Case 1

        Me.cmdAdmin.Enabled = True
        Me.cmdIad1.Enabled = True
        Me.cmdMgmt.Enabled = True
        
    Case 2

        Me.cmdIad1.Enabled = True

    Case 3
    
        Me.cmdMgmt.Enabled = True
    
End Select
 
Last edited:
Works like a champ. Thanks a ton!
 

Users who are viewing this thread

Back
Top Bottom