Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2004, 02:55 PM
Registered User
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old May 19th, 2004, 02:05 AM
Authorized User
 
Join Date: May 2004
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A quick and dirty observation without thinking too much about it....

Your code:
Quote:
quote:If strUserLevel = 2 Then
   .cmdOpenDMJIform.Visible = False
   .DMJobTrackinglabel.Visible = False

You have declared strUserLevel as String. Do you need to change
FROM: If strUserLevel = 2
TO: If strUserLevel = "2"

and later on

FROM: If strUserLevel = 1
TO: If strUserLevel = "1"
 
Old May 19th, 2004, 01:31 PM
Registered User
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Bob. I actually changed my declared statement for strUserLevel from String to Variant and that seemed to do the trick. But yours would work also.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error-0x800A000D-Type mismatch kishy449 Classic ASP Basics 0 July 23rd, 2007 04:48 AM
Type Mismatch error Sheraz Khan Classic ASP Basics 0 May 16th, 2007 08:12 AM
vb DLOOKUP function and dialog box error bluezcruizer Beginning VB 6 2 January 18th, 2007 04:25 PM
CreateObject Type mismatch error Deepmala Classic ASP Professional 1 February 7th, 2006 04:28 AM
Split Function type mismatch error nikotromus Access VBA 4 August 19th, 2004 12:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.