Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 14th, 2004, 02:55 PM
Registered User
Join Date: May 2004
Location: , , .
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.


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
If strUserLevel = 1 Then
   .cmdOpenIBTform.Visible = False
   .cmdOpenScriptTrackform.Visible = False
   .IBtrackinglabel.Visible = False
   .ScriptTrackinglabel.Visible = False
   End If
End If
End With

End Sub

Reply With Quote
  #2 (permalink)  
Old May 19th, 2004, 02:05 AM
Authorized User
Join Date: May 2004
Location: , NH, USA.
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts

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

Your code:
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"
Reply With Quote
  #3 (permalink)  
Old May 19th, 2004, 01:31 PM
Registered User
Join Date: May 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

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.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 09:57 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.