A
Annie
Hello,
I have a form where I have added code to the OnOpen design
of the form to check certain security levels and usernames
to distinguish if a person has the rights to read the form.
I have added two fields to my employee table Username and
Security Level. The code below works but when there is no
username or security level for a particular person I get
an error saying no current record. The code with the
asterix is what I added in to try and solve this problem
the rest of the code works if there is a username and
level.
I somehow want it to check to see if there is no username
or security level then I want to display a msg and then
just exit the Sub.
Private Sub Form_Open(Cancel As Integer)
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strUserName As String
Dim strUserPRI As String
Dim intUserSecurityLevel As Integer
strUserName = fOSUserName
strSQL = "SELECT EMPLOYEE.UserName, EMPLOYEE.PRI_SN,
Employee.SecurityLevel" & _
" FROM EMPLOYEE Where Employee.UserName = '" & strUserName
& "';"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset,
dbSeeChanges)
*If IsNull(intUserSecurityLevel) Or IsNull(strUserPRI) Then
*MsgBox "You are not an active member of CFEC. Please
contact the DBA"
*DoCmd.Close
*ExitSub
*End If
strUserPRI = rs!PRI_SN
intUserSecurityLevel = rs!SecurityLevel
strUserName = rs!UserName
If intUserSecurityLevel <> 3 And intUserSecurityLevel
<> 4 Then
DoCmd.Close
MsgBox "You do not have sufficient permissions to open
this form."
Exit Sub
End If
End Sub
Thanks for any help!
I have a form where I have added code to the OnOpen design
of the form to check certain security levels and usernames
to distinguish if a person has the rights to read the form.
I have added two fields to my employee table Username and
Security Level. The code below works but when there is no
username or security level for a particular person I get
an error saying no current record. The code with the
asterix is what I added in to try and solve this problem
the rest of the code works if there is a username and
level.
I somehow want it to check to see if there is no username
or security level then I want to display a msg and then
just exit the Sub.
Private Sub Form_Open(Cancel As Integer)
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strUserName As String
Dim strUserPRI As String
Dim intUserSecurityLevel As Integer
strUserName = fOSUserName
strSQL = "SELECT EMPLOYEE.UserName, EMPLOYEE.PRI_SN,
Employee.SecurityLevel" & _
" FROM EMPLOYEE Where Employee.UserName = '" & strUserName
& "';"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset,
dbSeeChanges)
*If IsNull(intUserSecurityLevel) Or IsNull(strUserPRI) Then
*MsgBox "You are not an active member of CFEC. Please
contact the DBA"
*DoCmd.Close
*ExitSub
*End If
strUserPRI = rs!PRI_SN
intUserSecurityLevel = rs!SecurityLevel
strUserName = rs!UserName
If intUserSecurityLevel <> 3 And intUserSecurityLevel
<> 4 Then
DoCmd.Close
MsgBox "You do not have sufficient permissions to open
this form."
Exit Sub
End If
End Sub
Thanks for any help!