Default CurrentUser when not opening form

  • Thread starter Thread starter Carl Colijn
  • Start date Start date
C

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
 
Lynn said:
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
 
Back
Top