Dlookup function giving Type Mismatch error
Hi everyone,
This is my first post on the Wrox site.
Here's my Access problem.
I have this Dlookup routine attached to the OnLoad
function of a Startup Form.
The UserLevel of the current user is checked against a
table at the time they login, this person should exist in
one of 2 tables.
Their assigned UserLevel# determines what controls they
see on the Startup form.
The code works fine if the user belongs to one of the 2
tables, but it gives a Type Mismatch error when it can't
find a user on one of the lists.
I figured the "ElseIf" statement with the ""
value and the proceeding "MsgBox" function would have
helped to take care of that, but it doesn't.
I can't seem to figure out what is exactly wrong. I've
tried different If..Then scenarios and nothing seems to
work properly.
Any help would be appreciated.
Thanks.
Ron (See routine below)
---------------------------------------------------------
Private Sub Form_Load()
Dim strUserLevel As String, strUser As String
strUser = CurrentUser()
strUserLevel = Nz(DLookup
("pUserLevel", "[tblProjectMgrs]", _
"ProjectName=""" & strUser & """"), "") 'This lookup checks
users in table one. All users in this table are assigned a UserLevel 1 value
With Me
If strUserLevel = "" Then
strUserLevel = Nz(DLookup"
tUserLevel", "[refTMSStrategyMgr]", _
"StrategyMgr=""" & strUser & """"), "") 'This second lookup checks table 2 and all users in this table are assigned a Userlevel 2 value
If strUserLevel = 2 Then
.cmdOpenDMJIform.Visible = False
.DMJobTrackinglabel.Visible = False
ElseIf strUserLevel = "" Then
MsgBox "User" & CurrentUser() & "is
not in either table." & _
"Please contact the system Admin to
add you to the appropriate table.", vbOKOnly
.cmdOpenIBTform.Visible = False
.cmdOpenScriptTrackform.Visible = False
.IBtrackinglabel.Visible = False
.ScriptTrackinglabel.Visible = False
.cmdOpenDMJIform.Visible = False
.DMJobTrackinglabel.Visible = False
End If
Else
If strUserLevel = 1 Then
.cmdOpenIBTform.Visible = False
.cmdOpenScriptTrackform.Visible = False
.IBtrackinglabel.Visible = False
.ScriptTrackinglabel.Visible = False
End If
End If
End With
End Sub
|