DLookup Problem

J

John C.

Upon opening my DB, I have code to lookup the users ID in
a table to return their full name.

If the user is not listed in the table, the code hangs up.

I have an "onerror" statement, but it is not activated for
some reason.

HERE IS MY TEST CODE:
MsgBox 1

varUserName = DLookup("[FullName]", "tblUsers", "[UserID]
= '" & varUserID & "'")

MsgBox 2

I receive Msgbox 1, but nothing happens after the
varUserName line.


ugggH, HELP please.
 
E

Eric Butts [MSFT]

Hi John,

The error you receive is the result of "varUserName" is Null.

Here's sample code that I used that should work for you. If you want to go
directly to MsgBox 2 regardless then use "On Error Resume Next"

Function testout()
On Error GoTo myError

Dim varStr As String

MsgBox 1
varUserName = DLookup("[FullName]", "tblUsers", "[UserID] = '" &
varUserID & "'")
MsgBox 2

Exit Function
myError:
MsgBox "some error"
End Function


I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."

This posting is provided "AS IS" with no warranties, and confers no rights


--------------------
| Content-Class: urn:content-classes:message
| From: "John C." <[email protected]>
| Sender: "John C." <[email protected]>
| Subject: DLookup Problem
| Date: Sun, 15 Aug 2004 22:49:12 -0700
| Lines: 22
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcSDVMHhFw3hJfFJQNKuxAfhIoguWg==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.access.formscoding
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.access.formscoding:242301
| NNTP-Posting-Host: tk2msftngxa14.phx.gbl 10.40.1.166
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| Upon opening my DB, I have code to lookup the users ID in
| a table to return their full name.
|
| If the user is not listed in the table, the code hangs up.
|
| I have an "onerror" statement, but it is not activated for
| some reason.
|
| HERE IS MY TEST CODE:
| MsgBox 1
|
| varUserName = DLookup("[FullName]", "tblUsers", "[UserID]
| = '" & varUserID & "'")
|
| MsgBox 2
|
| I receive Msgbox 1, but nothing happens after the
| varUserName line.
|
|
| ugggH, HELP please.
|
|
 

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

Similar Threads

DLookup Error 3
Using DLOOKUP in code entries 7
Dlookup - new record 5
Another DLOOKUP question 2
DLookup Help 4
Dlookup on form - help please 2
dlookup criteria & related 8
Dlookup on Continuous Sub 4

Top