Change startup based on user

Rob.Mills

Registered User.
Local time
Today, 18:15
Joined
Aug 29, 2002
Messages
871
How would I set a database to display certain toolbars at startup based on certain user accounts?
 
If you are using Access security, you can use the CurrentUser function to test who gets to see which toolbars.

If CurrentUser = "designer" Then
DoCmd.ShowToolbar "Custom Toolbar #1", acToolbarYes
DoCmd.ShowToolbar "CloseReport", acToolbarYes
DoCmd.ShowToolbar "Database", acToolbarYes
ElseIf CurrentUser = "Loosers" Then
DoCmd.ShowToolbar "Custom Toolbar #1", acToolbarNo
DoCmd.ShowToolbar "CloseReport", acToolbarYes
DoCmd.ShowToolbar "Database", acToolbarNo
Else
DoCmd.ShowToolbar "Custom Toolbar #1", acToolbarNo
DoCmd.ShowToolbar "CloseReport", acToolbarNo
DoCmd.ShowToolbar "Database", acToolbarNo
End If

HTH
 
I've never setup code for a database startup. Where would I place this code?

And can you set it up to determine if a user is part of a certain group and set this code based on groups?

Thanks
 
Where to start? Do you have security set up on your database? If you do when ghudson puts a name (designer, looser, ect..) in the code he is referring to your security group names. By putting your security group names here and putting in the names of the appropriate toolbars then putting this code in the On Open event of you form the appropriate toolbars will be displayed based on the user signing into the database. Todo so open your form in design view and click the little box in the top left hand corner of the form. Display the form properties. Scroll down until you see "On Open". Click to the right of the box. Select code builder from the pop up menu. Cut and paste the code (do not include HTH at bottom) into the VBA window. Make your changes. Click the "compile" button. No errors, great! Click the "save" button. Exit VBA and database. Log back in and bingo your there.

Don't have security (bad, very bad) then you could substitute your user names for the security group names.

Autoeng
 
The CurrentUser function will let you test what workgroup the user has signed into the database with.

I would put the code in the OnOpen event of your main form.

My example above is testing if the user logged into the db as a "designer" or "Loosers" and show/hide the toolbars as defined in the IF statement. If not, then the else statement will hide the three toolbars.

HTH
 
I'm in deep

Thought I'd try the access security wizard as suggested. Ran through but now I cannot access ANY of my databases. What have I done?

Signed

Stressed.

I've printed out the snapshot but it doesn't seem to help much.

Any advise much apreciated.
 
Last edited:
Ah i done that a few weks ago

I think if i recall the only way i found around it was to create a new database and import all forms, tables, queeries and then the data.

As i said it was a fewe weeks ago but i think that is what i done.

I was getting brave again on security and going to have anotheer attempt at it however you post has reminded me of the trouble i can get into.

best of luck
 
AArgh !!

I was wrong !!

I have now stuffed mine up the same way, it is telling me i do not have user permissions. and i get the same when trying to import.

Why did i mess with it again, i should have left it alone.

let me know oldsoftboss if you get sorted and i will do the same.

Cheers

bone head ( by name and nature)
 
Did you creat a shortcut to your desktop when using the security wizard. That is the only way to access the database now. The short cut contains a command to start the database with the appropriate security file. If you have the shortcut use it. Don't have it?, let's create one. On your desktop create new shortcut and in the comman line browse to your database but don't stop yet. Display the shortcut for the database and in command line add this;

/wrkgrp location of your secured.mdw\secured.mdw
example (c:\my documents\mydatabase.mdb /wrkgrp c:\my documents\secured.mdw)

Now try to access the database with the shortcut. If this didn't work let me know and we'll try some more common mistakes when setting up security.

Autoeng
 
Access automatically put a shortcut on my desktop but there was no mention of it. As my desktop has a background pic and dozens of icons I didn't even see it. Would have been nice to notice this before I went to the trouble of deleting the security file, creating a new one and stressing till about 2.00am

You live and learn:(

Dave.
 
Oldsoftboss:

I cannot stress enough that you read up on security. This episode will not be the end of your troubles if you don't become very familar with how security works, what the different parts of it are and how to set it up properly. Check out the Security faqs posted on www.tek-tips.com under Microsoft Access: Other Topics especially those posted by tlbroadbent. There is even a link to a security tutorial.

Good luck (and back up)

Autoeng
 
Many thanks will also follow links

if a short cut on your desk top is going to be the only way to access the data base then this is more problematic as my data base is on a company server, I am lucky accessing the system through a PC, however most people do not and do not have a desk top as such.

it looks like i may have to look at otherways of creating user preferences and access. hopwfull i may discover something throught hte links. would also welcome any suggestions
 
ghudson said:
If you are using Access security, you can use the CurrentUser function to test who gets to see which toolbars.

If CurrentUser = "designer" Then
DoCmd.ShowToolbar "Custom Toolbar #1", acToolbarYes
DoCmd.ShowToolbar "CloseReport", acToolbarYes
DoCmd.ShowToolbar "Database", acToolbarYes
ElseIf CurrentUser = "Loosers" Then
DoCmd.ShowToolbar "Custom Toolbar #1", acToolbarNo
DoCmd.ShowToolbar "CloseReport", acToolbarYes
DoCmd.ShowToolbar "Database", acToolbarNo
Else
DoCmd.ShowToolbar "Custom Toolbar #1", acToolbarNo
DoCmd.ShowToolbar "CloseReport", acToolbarNo
DoCmd.ShowToolbar "Database", acToolbarNo
End If

HTH

Is there a way to do the example code, but querying the group that the current user is a part of? It'd be much better if I could have the toolbars be hid based upon group, not based upon an individual user. Thanks!
 
Answered my own question

tembenite said:
Is there a way to do the example code, but querying the group that the current user is a part of? It'd be much better if I could have the toolbars be hid based upon group, not based upon an individual user. Thanks!

I answered my own question with a different thread. This is the code I came up with based upon that thread.

Function IsInGroup(grpName As String) As Boolean
Dim daGroups As Object
Set daGroups = DBEngine.Workspaces(0).Users(CurrentUser).Groups
IsInGroup = False
For Each x In daGroups
If x.Name = grpName Then IsInGroup = True
Next x
End Function 'Returns True or false depending on if the current user is in a given group

The other thread is Here
 

Users who are viewing this thread

Back
Top Bottom