By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

CurrentUser() returns null

P: n/a
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

Sep 4 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
(re-posting, as my original reply hasn't appeared)

"Mourad" wrote in message
news:92**********************************@i20g2000 prf.googlegroups.com...
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?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Sep 4 '08 #2

P: n/a
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
Sep 4 '08 #3

P: n/a
"Mourad" <mo************@gmail.comwrote in message
news:a3**********************************@a18g2000 pra.googlegroups.com...
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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Sep 4 '08 #4

P: n/a
"Mourad" <mo************@gmail.comwrote in message
news:a3**********************************@a18g2000 pra.googlegroups.com...
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.

Sep 5 '08 #5

P: n/a
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
Oct 23 '08 #6

P: n/a
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.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"Mourad" <mo************@gmail.comwrote in message
news:78**********************************@s50g2000 hsb.googlegroups.com...
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

Oct 23 '08 #7

P: n/a
Darn double negatives!

I meant to say "I don't believe it's a bug"!

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.comwrote in message
news:OV**************@TK2MSFTNGP06.phx.gbl...
>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.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"Mourad" <mo************@gmail.comwrote in message
news:78**********************************@s50g2000 hsb.googlegroups.com...
>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


Oct 23 '08 #8

P: n/a
On Oct 23, 3:50*pm, Mourad <mourad.bara...@gmail.comwrote:
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).
Oct 23 '08 #9

P: n/a
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
Oct 23 '08 #10

P: n/a

"Mourad" <mo************@gmail.comescreveu na mensagem
news:78**********************************@s50g2000 hsb.googlegroups.com...
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
Oct 25 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.