CurrentUser() returns null

M

Mourad

Hi All,

CurrentUser() returns null when called from a form event handler, at
least from Form_Open()!

However, it works fine in other forms!

Use Application.CurrentUser seem to work, but I'd rather get
CurrentUser() to work, since there are so many calls to it.

Thanks for reading,

Mourad
 
D

Dirk Goldgar

(re-posting, as my original reply hasn't appeared)

"Mourad" wrote in message
Hi All,

CurrentUser() returns null when called from a form event handler, at
least from Form_Open()!

However, it works fine in other forms!

Use Application.CurrentUser seem to work, but I'd rather get
CurrentUser() to work, since there are so many calls to it.


My guess is that you have something else named CurrentUser that is in scope
at the time you call it from this form's Open event. Do you have a control,
field, or variable named CurrentUser?
 
M

Mourad

Thanks Dirk,

Nop! There is no user defined CurrentUser() anywhere in the code.

The debugger even does not step into CurrentUser() function!

It still returns null!!

Thanks,

Mourad
 
D

Dirk Goldgar

Mourad said:
Thanks Dirk,

Nop! There is no user defined CurrentUser() anywhere in the code.

The debugger even does not step into CurrentUser() function!


If the "CurrentUser" function you are referring to is the built-in one, I
wouldn't expect the debugger to step into it.

If you click Debug ->Compile in the VB editor, are any compile errors found?

The fact that it works in other forms but not in one particular form
strongly suggests that there's something about that particular form that is
the problem. If you create a new database, import that form and any
necessary supporting tables, queries, and modules into it, does the call to
CurrentUser work on the form in that database?

If not, and if you want to send me a (zipped) copy of that database to look
at, you can send it to the address you get by removing "NO SPAM" and
".invalid" from the reply address of this message.
 
K

Keith Wilby

Mourad said:
Thanks Dirk,

Nop! There is no user defined CurrentUser() anywhere in the code.

The debugger even does not step into CurrentUser() function!

It still returns null!!

What happens if you type ?CurrentUser into the immediate window?

Keith.
 
B

Brendan Reynolds

Mourad said:
Thanks Dirk,

Nop! There is no user defined CurrentUser() anywhere in the code.

The debugger even does not step into CurrentUser() function!

It still returns null!!

Thanks,

Mourad


The data type of the return value of the built-in CurrentUser() function is
String, which can never be Null, so if you have something called
CurentUser() that is returning Null, it is not the built-in function, it
can't be, as in order to return Null the data type of its return value has
to be Variant.
 
M

Mourad

Thank you all,

It was found that the underlying query of the form has a column with
the same name, CurrentUser! It seems that Access refers to this one
when CurrentUser() function is called! So when the query returns no
rows, CurrentUser() returns NULL, but if there is one or more rows, it
returns a contents of some row (didn't verify which)

I doubt this is by design! I believe it is an Access bug!

Mourad
 
D

Douglas J. Steele

I don't believe it's not a bug.

If you mistaken choose to name something with a reserved name, Access will
try to respect your object. This allows you to override built-in
functionality (although realistically it's not a good idea).

For a comprehensive list of names to avoid, see what Allen Browne has at
http://www.allenbrowne.com/AppIssueBadWord.html Note that there's also a
link at the top of the page to a utility that will help identify names
you've used by mistake.
 
L

lyle fairfield

Thank you all,

It was found that the underlying query of the form has a column with
the same name, CurrentUser! It seems that Access refers to this one
when CurrentUser() function is called! So when the query returns no
rows, CurrentUser() returns NULL, but if there is one or more rows, it
returns a contents of some row (didn't verify which)

I doubt this is by design! I believe it is an Access bug!

Mourad

When we preface a function with the Class of which it is a member
Access can often differentiate between objects with the same name.
Otherwise it uses the first one it comes to as it searches through all
the classes and pointers currently in scope; I believe this search is
ordered descending on creation time.
You may be able to help Access/VBA understand what you want with
Access.CurrentUser() or Application.CurrentUser(); this syntax will
tell Access/VBA where to look.
I often use VBA.Date() as, despite many warnings that the sky will
fall I like to call my Date fields, "Date", unless I call them
"Redhead" but that is another story. Works swimmingly!
There's no bug here. Access is not Aladdin's lamp. It cannot magically
decide which CurrentUser you want.
BTW, I recall only one genuine bug posted here in CDMA, (many years
ago).
 
M

Mourad

If Access cannot distinguish "CurrentUser" from "CurrentUser()" then
you have a point! May be it is the way Access works.

But they should not the same: the first is a reference to a variable,
table field, or an object property, but the later is a Function Call!

This concept is in some other languages like C++!

Thanks for your input

Mourad
 
C

claudia

Mourad said:
Thank you all,

It was found that the underlying query of the form has a column with
the same name, CurrentUser! It seems that Access refers to this one
when CurrentUser() function is called! So when the query returns no
rows, CurrentUser() returns NULL, but if there is one or more rows, it
returns a contents of some row (didn't verify which)

I doubt this is by design! I believe it is an Access bug!

Mourad
 

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