color test
I know this is an old issue but this is how I handled it. On logon I retrieve the users access type from a table and open my next form. when the form loads button colors are set to disable the use of buttons that the user does not have access to. then when they click the button i test for the disabled color and if the button has that color set it simply exits the sub. In doing it this way the hover colors etc still work, but when clicked on it simply does nothing.
'Form Load event
Private Sub Form_Load()
Dim rs As Recordset
Dim lngLGrey As Long, lngDGrey As Long
lngLGrey = RGB(120, 120, 120)
lngDGrey = RGB(60, 60, 60)
Set rs = CurrentDb.OpenRecordset("Users", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & LCase(Environ$("UserName")) & "'"
Select Case rs!UserType
Case 1
Me.btnReg.ForeColor = lngLGrey
Me.btnReg.BackColor = lngDGrey
Me.btnAdmin.ForeColor = lngLGrey
Me.btnAdmin.BackColor = lngDGrey
Case 2
Me.btnInstructor.ForeColor = lngLGrey
Me.btnInstructor.BackColor = lngDGrey
Me.btnAdmin.ForeColor = lngLGrey
Me.btnAdmin.BackColor = lngDGrey
Case 3
Me.btnAdmin.ForeColor = lngLGrey
Me.btnAdmin.BackColor = lngDGrey
Case 4
Case Else
Me.btnInstructor.ForeColor = lngLGrey
Me.btnInstructor.BackColor = lngDGrey
Me.btnReg.ForeColor = lngLGrey
Me.btnReg.BackColor = lngDGrey
Me.btnAdmin.ForeColor = lngLGrey
Me.btnAdmin.BackColor = lngDGrey
GoTo Invalid
End Select
Exit Sub
Invalid:
Dim LResponse As Integer
LResponse = MsgBox("Invalid UserType", vbOKOnly, "Invalid Access")
End Sub
'button click event
Private Sub btnAdmin_Click()
If Me.btnReg.ForeColor = RGB(120, 120, 120) Then Exit Sub
DoCmd.OpenForm "Admin"
End Sub
|