I have a main form with several buttons that take end-users to various other forms in the database. All forms are accessible and available to my users and admins except for 1. There is a button on the main page that is a data entry button. I coded the onclick event for this button but those that have just user access can still click the button and get to this area, however the data entry form is disabled. I really would like the button to be disabled for anyone without an admin level. Here is my code. Is there a way to alter it at all?
mainform code
Code:
Private Sub Form_Load()
Dim sPermit As String
Dim iAccess As Integer
Dim Ctl As Access.Control
Me.txtUser = Environ("UserLogin")
If IsNothing(Me.txtUser) Then
sPermit = "ReadOnly"
Else
sPermit = UserSecurity(Me.txtUser)
End If
Select Case sPermit
Case "User"
iAccess = User
Case "Admin"
iAccess = Admin
Case Else
iAccess = ReadOnly
End Select
Me.txtLevel = iAccess
Me.txtLevel.Requery
End Sub
Private Function UserSecurity(sUser As String)
UserSecurity = DLookup("UserSecurity", "user", "UserLogin='" & Forms!switchboard!txtUser & "'")
End Function
Private Sub txtLevel_Click()
Dim sForm As String, sType As String
sForm = Me.lstlevel.Column(1)
sType = Me.lstlevel.Column(2)
Select Case sType
Case "Form"
DoCmd.OpenForm sForm
Case "Report"
DoCmd.OpenReport sForm, acViewPreview
End Select
End Sub
data entry form code
Code:
Private Sub Form_Load()
If Forms!switchboard!txtLevel = User Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If
End Sub
I can see now the problem is because the user level stuff is on the actual data entry form and needs to be associated with that button, however the button already has a click event to go to the data entry form. There is no way to do an on enter for the same command is there? or can I maybe put the if forms! statement into my main form somewhere? Or how about doing some sort of call function on my main form that looks at this code? Is that possible?