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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open different forms after checking user id

Status
Not open for further replies.

tobymom

Programmer
Aug 18, 2006
36
US
Hello,

I'd like to do something similar to this...would someone please shed some light on me? Thanks in advance.

if userid = userA then
open form A
else if userid = userB then
open form B
else if (..and so on)

I guess we can use switch for this purpose.

OS: XP pro
Office XP
 
How are ya tobymom . . .

You already have the [blue]If Then[/blue] schema and have mentioned [blue]Switch[/blue] as well.

Go for it! [thumbsup2] . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Your pseudo-code is correct, you just need to translate it to VBA.

Assuming that "userid" and "UserA" are the actual variables to be compared, the only thing you need to change is:

DoCmd.OpenForm "formA"

"Select Case" is the VBA equivalent of switch.

Check online help for the details.

 
Thank you theaceman1 and joeatwork for your input. I appreciate it very much.

I should've explained it in detail...What I wanted to do was:

There are two userids at work in use: "operation" and "sales" and I want them to have separate switch boards if possible.

Let's say "operation" login then switchboardA should open automatically.

If "sales" logs-in, then switchboardB should open automatically.

I taught myself this Access/VBA thing by googling alot but couldn't find something like this. Thanks alot for your time.
 
where are these userID's comming from? Are they in form controls are from a recordset. What (if anything) does user input have to do with this process?

.....
I'd rather be surfing
 
Thanks for asking.

I am not familiar with MS Access security and login. Someone was developing this Access and I took over recently.

Anyway,

This is what users do:

Click a shortcut which target looks like this:
"C:\Program Files\Microsoft Office\Office10\MSACCESS.EXE" /WRKGRP "C:\op_files\ENV\Secured.mdw"

Then Access window comes up, choose a file to open, then login windows comes up.

They typein user id and password then switchboard comes up.

Those user ids can be found under Tools>Security>User and Group Accounts when I login as "Admin"

Hope this clarifies... Thank you.
 
so is the user associated with the windows login? Is there a table in your DB that tracks user information, like an employee table.

I have not worked with that type of security.

You can access the username and the server group membership of the windows user who is currently logged in, would that be able to determine which person can open which switchboard?

.....
I'd rather be surfing
 
user is not associated with the windows login.

When I said, "those user ids can be found..." I meant under MS Access, I can see them when I login as Admin within Access.

I should look up if there's a hidden table that manages userid/password in this case.

Thank you for your help.
 
if not, I would suggest using a local table within access to store employee data. That is what I do, then I use my own login form to compare with the window login informations and store the employee's information globally once he/she logs in.

.....
I'd rather be surfing
 
that might be a good idea. I will look into that.
Thank you!
 
this might get you started


the following tests to see if a username(supplied) is a memeber of a supplied windows server group

Code:
Public Function DMS_User_InGroup(strGroup As String, strUser As String) As Boolean
''assumes user is already logged in and this test is to be applied against current user
Dim objIADsUser As IADsUser
Dim objGroup As IADsGroup
Dim strOutput As String

    strOutput = "WinNT://" & Environ("USERDOMAIN") & "/" & strUser & ",User"
    Set objIADsUser = GetObject(strOutput)
    
    For Each objGroup In objIADsUser.Groups
        If strGroup = objGroup.Name Then
            GoTo Exit_Function
        End If
    Next objGroup
    Set objIADsUser = Nothing
    DMS_User_InGroup = False
    Debug.Print "Not in group"
    Exit Function
    
Exit_Function:
    Set objIADsUser = Nothing
    DMS_User_InGroup = True
    Debug.Print "In group"
End Function


the following code is an example of some of the windows environment variables that you have access to:

Code:
'''just an example of the available environment variables
Public Function DMS_EnvironVaraibles()
    Dim User As String
    Dim user2 As String
    Dim computer As String
    Dim Domain As String
    Dim proc As String
    Dim os As String
    Dim windir As String
    Dim i As Integer
    
    User = Environ("USERNAME")
    Debug.Print "user =           " & User
    computer = Environ("COMPUTERNAME")
    Debug.Print "comp =           " & computer
    Domain = Environ("LOGONSERVER")
    Debug.Print "Logon server =   " & Domain
    Domain = Environ("USERDOMAIN")
    Debug.Print "user domain =    " & Domain
    proc = Environ("NUMBER_OF_PROCESSORS")
    Debug.Print "proc =           " & proc
    os = Environ("OS")
    Debug.Print "OS =             " & os
    windir = Environ("windir")
    Debug.Print "windir =         " & windir
    i = 1
    For i = 1 To 31
        Debug.Print i
        Debug.Print Environ(i)
        i = i + 1
    Next

End Function

.....
I'd rather be surfing
 
Take a look at the Tools/startup/display form/page setting too. Instead of opening a switchboard you could have a initial form load which in turn will open the correct switchboard.

Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
I would stick with the Access security since that is already implemented and presumably working.

To see what the user is logged in as, use CurrentUser.

Therefore, your original code would be something like:
Code:
if CurrentUser = "Sales" then
   DoCmd.OpenForm "form_A"
else if CurrentUser = "Operations" then
   DoCmd.OpenForm "form_B"
....
However, "Sales" and "Operations" sound like groups, in which case you need alternative code to find out if the user is in one of those groups.

 
jordanking: Thank you very much for the sample code.

ProgramError: Thank you for the tip. It'll definitly help me in this situation.

JoeAtWork: "CurrentUser" is the one I was looking for!!! THANKS!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top