Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHERE TO GO ? 2

Status
Not open for further replies.

spudmizer

Technical User
Jul 25, 2002
35
US
Is there a way to direct based on access level where a user goes after they log in??

What I am wanting...

User opens the database and enters a user name and password,
then I want it to depending on their "Security Level" go to one of three pages, UserScreen, ManagerScreen, AdminScreen.


What would you do for a Klondike Bar?
 
Hi,

I am assuming that you already have the user login section built. Try this:
- TextBoxFromForm should be the name of the textbox from the login form that the user enters their username.

Dim UserLevel

UserLevel = DLookup("[UserLevel]", "Users", "[UserName] = [TextBoxFromForm]")

Select Case UserLevel
Case 1
DoCmd.OpenForm "UserScreen"
DoCmd.close acForm, "LoginForm"
Case 2
DoCmd.OpenForm "ManagerScreen"
DoCmd.close acForm, "LoginForm"
Case 3
DoCmd.OpenForm "AdminScreen"
DoCmd.close acForm, "LoginForm"
End Select

jbehrne If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
You could do it by checking to see if the user is a member of a specific group (security group). Where each group is assigned to certain tasks. The function below will let you know if the user is a member of the group. Note that a user could be a member of more than 1 group. Your code would look something like this:

Dim bolMemberOfGroup as Boolean

If (UserBelongsToGroup = "Group1") then
DoCmd.OpenForm "form1"
ElseIf (UserBelongsToGroup = "Group2") then
DoCmd.OpenForm "form2"
blah blah blah

Here's the function UserBelongsToGroup

Function UserBelongsToGroup(strGroupName As String, Optional varCurrentUser As Variant) As Boolean

'********************************
'* Declaration Specifications *
'********************************

Dim wsp As Workspace
Dim grp As Group
Dim usr As User

Dim i As Integer
Dim bolAnswer As Boolean

Dim strCurrentUser As String

'****************
'* Initialize *
'****************

On Error GoTo ErrHandler

bolAnswer = False

If (IsMissing(varCurrentUser)) Then
strCurrentUser = CurrentUser
Else
strCurrentUser = CStr(varCurrentUser)
End If

Set wsp = DBEngine.Workspaces(0)
Set grp = wsp.Groups(strGroupName)
Set usr = wsp.Users(strCurrentUser)

'******************************************************************
'* Loop to determine if the User is part of the group specified *
'******************************************************************

For i = 0 To grp.Users.Count - 1
If grp.Users(i).Name = usr.Name Then
bolAnswer = True
GoTo ExitProcedure
End If
Next i

' wsp.Close

'********************
'* Exit Procedure *
'********************

ExitProcedure:

MMC_UserBelongsToGroup = bolAnswer

Exit Function

'****************************
'* Error Recovery Section *
'****************************

ErrHandler:

If Err = 3265 Then
MsgBox UCase(strGroupName) & " isn't a valid group name", vbExclamation
ElseIf Err = 3029 Then
MsgBox "The account used to create the workspace does not exist", vbExclamation
Else
MsgBox Err.Description, vbExclamation
End If

wsp.Close
resume ExitProcedure

End Function


 
I would create an AutoExec macro (which is launched at startup) and have the macro call the following function. (Create a new module and insert the following code.)

Function StartUp()

If (UserBelongsToGroup = "Group1") then
DoCmd.OpenForm "form1"
ElseIf (UserBelongsToGroup = "Group2") then
DoCmd.OpenForm "form2"
blah blah blah

End Function
 
Hi again

How do you get a macro to run on startup of a db.

Autexec!!! what the hell is that?

Excuse my ignorance, I have only started messing around with VBA lately. Its the job but dont have a clue what macros are or where to use them.
Also can I declare stuff in Macros/Modules that I use in more than one form rather than having to put it in every form etc...

Thanks for your time and patience.
S.
 
In tools - Startup, you will find a host of options allowing you to specify how your db opens.

autoexec is autoexecute, namely a macro that when called runs a specific command statement

Initially paste code to new module
set up new macro with runcode where parameters specify which piece of code.
then go to your startup options and specify that you want db to start by running macro.

ALan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top