AutoExec to open the right form for the user.

Brando

Enthusiastic Novice
Local time
Today, 04:04
Joined
Apr 4, 2006
Messages
100
Greetings,

I have finished creating a new database (my third) for my company and I am about to add user security. On start up, I would like to have a macro open one form for one department and a different form for the other department.

I don't even know where to start. Can you point me in a direction?

Thank you,
Brando
 
Thank you. I checked out the link and it gives me some direction to go on.
 
Hopefully its enough to get you started. Like I said, you can always ask here if you have any problems
 
Check out the link I provided, if you're still unsure you're better off starting your own thread and asking for more specific help.
 
I am still having a hard time with this one and would like to ask for more direction. dbDamo pointed me at a link on how to use the OpenFunction Action, but there is a critical piece that I am missing. I have searched all over the internet. I am really surprised this isn't a more common question.

I want to place a function in an autoexec macro that will open a particular form based on the user's user level. If I knew how to talk to the user security, I could create an If, Then statement or Case 1, Case 2 statement to achieve this. There are 3 user groups and 3 corresponding forms. There is no user table to refer to. Essentially, what I want to do is...

If UserGroup = "Group1" Then
Open.Form Group1Form

ElseIf UserGroup = "Group2" Then
Open.Form Group2Form

etc...

Thanks again for any help.
 
This really does become much simpler for you if you create a table of users with their username and group
 
While I appreciate the suggestion, this db has 80+ occasional users and has user level security. So an additional table of names would be burdensome.

My question is how do I get the AutoExec macro to run a function like:

Function GetCorrectForm()
Dim grp As Group
Dim usr As User
For Each usr In DBEngine(0).Users
For Each grp In usr.Groups
If grp.Name = "User" Then
If CurrentUser = usr.Name Then
DoCmd.OpenForm "frmUserSwitch"
Exit Function
ElseIf CurrentUser = "Admin" Then
DoCmd.OpenForm "frmAdminSwitch"
Exit Function
End If
End If
Next
Next
End Function
 
Personally to run code like that I would use a splash screen on open and run the code on form_load. You will still need to find a way to identify which users have which access level though.
 
Success!
I put the code in a module, called the function from the AutoExec macro, changed "User" to "Users", and it worked!

Anyway, with that minor change, and some error handling, the code works brilliantly. But I must say. I am very surprised that this is not a more commonly used function.
:)
 

Users who are viewing this thread

Back
Top Bottom