Home All Groups Group Topic Archive Search About

Default CurrentUser when not opening form

Author
12 Sep 2006 3:22 PM
Carl Colijn
Hi group,

I found a peculiar situation with my database.  When I first use CurrentDB
and then show Workspaces(0).UserName in a MsgBox, I get the name of the
logged in user.  However, when I do not first access CurrentDB and ask for
the value of Workspaces(0).UserName right away, I get "admin"...  Further
investigation reveals that "admin" really is the logged in user from then
on, at least as far as Access is concerned.  When I insert the following
code:
    Dim oThisDB As DAO.Database
    Set oThisDB = CurrentDb
right before the part where I start using Workspaces(0), all is fine and the
correct current user is recognized again...

Sometimes in my code I first use Workspaces(0) to get some things done
before using CurrentDB.  And since "admin" has no rights on my database, all
my error routines get triggered.  I know I can work around this issue by
first asking for CurrentDB, but I wondered what might be going on...  Is
this by design or is there something else going on?  I use Access 2003,
Dutch edition, and the current user logs in via a shortcut that specifies
the workgroup, username and password.

Thanks in advance,
Carl Colijn

Author
12 Sep 2006 3:54 PM
Lynn Trapp
Try using the CurrentUser() function in the place of Workspaces(0).UserName.

Show quoteHide quote
"Carl Colijn" <carl.col***@gmail.com> wrote in message
news:6c99b$4506d06e$d55db81c$19029@news.chello.nl...
> Hi group,
>
> I found a peculiar situation with my database.  When I first use CurrentDB
> and then show Workspaces(0).UserName in a MsgBox, I get the name of the
> logged in user.  However, when I do not first access CurrentDB and ask for
> the value of Workspaces(0).UserName right away, I get "admin"...  Further
> investigation reveals that "admin" really is the logged in user from then
> on, at least as far as Access is concerned.  When I insert the following
> code:
>    Dim oThisDB As DAO.Database
>    Set oThisDB = CurrentDb
> right before the part where I start using Workspaces(0), all is fine and
> the correct current user is recognized again...
>
> Sometimes in my code I first use Workspaces(0) to get some things done
> before using CurrentDB.  And since "admin" has no rights on my database,
> all my error routines get triggered.  I know I can work around this issue
> by first asking for CurrentDB, but I wondered what might be going on...
> Is this by design or is there something else going on?  I use Access 2003,
> Dutch edition, and the current user logs in via a shortcut that specifies
> the workgroup, username and password.
>
> Thanks in advance,
> Carl Colijn
>
Author
12 Sep 2006 4:38 PM
Carl Colijn
Lynn Trapp wrote:
Show quoteHide quote
> "Carl Colijn" <carl.col***@gmail.com> wrote in message
> news:6c99b$4506d06e$d55db81c$19029@news.chello.nl...
>> Hi group,
>>
>> I found a peculiar situation with my database.  When I first use
>> CurrentDB and then show Workspaces(0).UserName in a MsgBox, I get
>> the name of the logged in user.  However, when I do not first access
>> CurrentDB and ask for the value of Workspaces(0).UserName right
>> away, I get "admin"...  Further investigation reveals that "admin"
>> really is the logged in user from then on, at least as far as Access
>> is concerned.  When I insert the following code:
>>    Dim oThisDB As DAO.Database
>>    Set oThisDB = CurrentDb
>> right before the part where I start using Workspaces(0), all is fine
>> and the correct current user is recognized again...
>>
>> Sometimes in my code I first use Workspaces(0) to get some things
>> done before using CurrentDB.  And since "admin" has no rights on my
>> database, all my error routines get triggered.  I know I can work
>> around this issue by first asking for CurrentDB, but I wondered what
>> might be going on... Is this by design or is there something else
>> going on?  I use Access 2003, Dutch edition, and the current user
>> logs in via a shortcut that specifies the workgroup, username and
>> password. Thanks in advance,
>> Carl Colijn
>
> Try using the CurrentUser() function in the place of
> Workspaces(0).UserName.

Hi Lynn,

Well, it's not that I need the name of the CurrentUser, but I need to use
the default workspace (Workspaces(0)).  And directly accessing the default
workspace before accessing CurrentDB results in "admin" being the current
user from then on during the rest of the session, in stead of the actually
logged in user.  And it's not only that the name is wrong; the code also
operates under the credentials of the "admin" user (which is locked out of
the DB in my case).

Any ideas?  For now I execute the function
    Public Function SetCorrectUser() As Boolean
        Dim oThisDB As DAO.Database
        Set oThisDB = CurrentDb
        SetCorrectUser = True
    End Function
in an AutoExec macro (which also does the trick).  But I'd rather not have
to rely on this workaround...

Kind regards,
Carl Colijn
Author
12 Sep 2006 4:54 PM
Lynn Trapp
Carl,
Without using the CurrentDB reference you aren't going to know the user
logged in to Workspaces(0). However, CurrentUser() should return the logged
in user regardless.

Show quoteHide quote
"Carl Colijn" <carl.col***@gmail.com> wrote in message
news:8ed4e$4506e26d$d55db81c$4006@news.chello.nl...
> Lynn Trapp wrote:
>> "Carl Colijn" <carl.col***@gmail.com> wrote in message
>> news:6c99b$4506d06e$d55db81c$19029@news.chello.nl...
>>> Hi group,
>>>
>>> I found a peculiar situation with my database.  When I first use
>>> CurrentDB and then show Workspaces(0).UserName in a MsgBox, I get
>>> the name of the logged in user.  However, when I do not first access
>>> CurrentDB and ask for the value of Workspaces(0).UserName right
>>> away, I get "admin"...  Further investigation reveals that "admin"
>>> really is the logged in user from then on, at least as far as Access
>>> is concerned.  When I insert the following code:
>>>    Dim oThisDB As DAO.Database
>>>    Set oThisDB = CurrentDb
>>> right before the part where I start using Workspaces(0), all is fine
>>> and the correct current user is recognized again...
>>>
>>> Sometimes in my code I first use Workspaces(0) to get some things
>>> done before using CurrentDB.  And since "admin" has no rights on my
>>> database, all my error routines get triggered.  I know I can work
>>> around this issue by first asking for CurrentDB, but I wondered what
>>> might be going on... Is this by design or is there something else
>>> going on?  I use Access 2003, Dutch edition, and the current user
>>> logs in via a shortcut that specifies the workgroup, username and
>>> password. Thanks in advance,
>>> Carl Colijn
>>
>> Try using the CurrentUser() function in the place of
>> Workspaces(0).UserName.
>
> Hi Lynn,
>
> Well, it's not that I need the name of the CurrentUser, but I need to use
> the default workspace (Workspaces(0)).  And directly accessing the default
> workspace before accessing CurrentDB results in "admin" being the current
> user from then on during the rest of the session, in stead of the actually
> logged in user.  And it's not only that the name is wrong; the code also
> operates under the credentials of the "admin" user (which is locked out of
> the DB in my case).
>
> Any ideas?  For now I execute the function
>    Public Function SetCorrectUser() As Boolean
>        Dim oThisDB As DAO.Database
>        Set oThisDB = CurrentDb
>        SetCorrectUser = True
>    End Function
> in an AutoExec macro (which also does the trick).  But I'd rather not have
> to rely on this workaround...
>
> Kind regards,
> Carl Colijn
>