Dlookup function getting a Type Mismatch error

R

Ron

I have this Dlookup routine attached to the OnLoad
function of a Form (Got some good help yesterday with
designing the structure of it).
Anyway - it looks up the User Level of the current user
logged in at the time, who should exist in one of 2 tables.
Depending on their assigned UserLevel# determines what
controls they see on the Startup form.
The code works perfectly if the user belongs to one of the
tables, but it gives a "Type Mismatch" error if it can't
find a logged in user. The "ElseIf" statement with
a "MsgBox" function I thought would have helped to take
care of that, but it doesn't.
Can anyone see, judging by the code, why a "Type Mismatch"
would occur. I can't seem to figure it out.

Thanks.

Ron
---------------------------------------------------------

Private Sub Form_Load()

Dim strUserLevel As String, strUser As String

strUser = CurrentUser()
strUserLevel = Nz(DLookup
("pUserLevel", "[tblProjectMgrs]", _
"ProjectName=""" & strUser & """"), "")

With Me
If strUserLevel = "" Then
strUserLevel = Nz(DLookup"
tUserLevel", "[refTMSStrategyMgr]", _
"StrategyMgr=""" & strUser & """"), "")
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
 
R

Ron

Sorry about that Van. Didn't know if I had originally put
it in the right one.
-----Original Message-----
(replied in formscoding).

Please do not multi-post.

See The Access Web for efficient use of these newsgroups:

http://www.mvps.org/access/netiquette.htm

--
HTH
Van T. Dinh
MVP (Access)


I have this Dlookup routine attached to the OnLoad
function of a Form (Got some good help yesterday with
designing the structure of it).
Anyway - it looks up the User Level of the current user
logged in at the time, who should exist in one of 2 tables.
Depending on their assigned UserLevel# determines what
controls they see on the Startup form.
The code works perfectly if the user belongs to one of the
tables, but it gives a "Type Mismatch" error if it can't
find a logged in user. The "ElseIf" statement with
a "MsgBox" function I thought would have helped to take
care of that, but it doesn't.
Can anyone see, judging by the code, why a "Type Mismatch"
would occur. I can't seem to figure it out.

Thanks.

Ron
-------------------------------------------------------- -

Private Sub Form_Load()

Dim strUserLevel As String, strUser As String

strUser = CurrentUser()
strUserLevel = Nz(DLookup
("pUserLevel", "[tblProjectMgrs]", _
"ProjectName=""" & strUser & """"), "")

With Me
If strUserLevel = "" Then
strUserLevel = Nz(DLookup"
tUserLevel", "[refTMSStrategyMgr]", _
"StrategyMgr=""" & strUser & """"), "")
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


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top