Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171

    Enabling commands for different users

    Hello,


    I have two users in my database.
    Users : ABC and XYZ.
    In attached pic I want that if I login as a XYZ then command 7 and 8 should be disabled.
    What will be the procedure?
    Thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Only two users for this db?

    One way:
    Me.Command7.Visible = User = "ABC"
    Me.Command8.Visible = User = "ABC"

    How and where do you set variable User? This could be a textbox on a form that never closes (I do this - MainMenu never closes). Or can be a global variable - global variables are a nuisance when debugging. Do users login with username and password? Is this a split db? Is backend on a network server?

    There are ways to make this more dynamic and allow for more users. Involves use of a UserInfo table. Can use intrinsic function Envriron() to get username from the network. Syntax:
    Environ("USERNAME") - yes, type EXACTLY as shown. Access does not recognize Environ() but VBA does.

    Then use that value to match record in table. Table can have field for user permissions (admin, manager, staff). Set control visibility based on permissions.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Yes June, the users will select their user names and enter passwords.
    then they will go inside database.
    Right now this is a simple database.This is not a split database nor backend on server.

    This is my coding for users login Command.
    Option Compare Database
    Option Explicit
    Dim intLogonAttempts As Integer

    Private Sub cboemployee_AfterUpdate()
    'After selecting user name set focus to password field
    Me.TXTPASSWORD.SetFocus

    End Sub

    Private Sub cmdlogin_Click()
    'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboemployee) Or Me.cboemployee = "" Then
    MsgBox "Please Enter User Name", vbOKOnly, "Required Data"
    Me.cboemployee.SetFocus
    Exit Sub
    End If

    'Check to see if data is entered into the password box

    If IsNull(Me.TXTPASSWORD) Or Me.TXTPASSWORD = "" Then
    MsgBox "Please Enter Your Password", vbOKOnly, "Required Data"
    Me.TXTPASSWORD.SetFocus
    Exit Sub
    End If

    'Check value of password in tblEmployees to see if this
    'matches value chosen in combo box

    If Me.TXTPASSWORD.Value = DLookup("strEmpPassword", "tblEmployees", _
    "[lngEmpID]=" & Me.cboemployee.Value) Then

    lngMyEmpID = Me.cboemployee.Value

    'Close logon form and open splash screen


    DoCmd.OpenForm "SWITCHBOARD"
    DoCmd.Close acForm, "logon", acSavePrompt


    Else
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
    "Invalid Entry!"
    Me.TXTPASSWORD.SetFocus
    End If

    'If User Enters incorrect password 3 times database will shutdown

    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
    MsgBox "You do not have access to this database.Please contact admin.", _
    vbCritical, "Restricted Access!"
    Application.Quit
    End If
    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    How do you want to hold the username after login? Do you want to populate a textbox on SWITCHBOARD? One method could be to bind the SWITCHBOARD form to Users table. Then use WHERE CONDITION of OpenForm to filter SWITCHBOARD recordset.

    DoCmd.OpenForm "SWITCHBOARD", , , "USERNAME='" & Me.USERNAME & "'"

    Bind a textbox on SWITCHBOARD to USERNAME field.

    Then code in any form can refer to the SWITCHBOARD (as long as it never closes) for criteria.

    If Forms!SWITCHBOARD.USERNAME = "ABC" Then
    ...
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Hello June,
    In attached image there is my user name table and switchboad.
    I want that if user is abc then command7 should not be visible or not enabled.
    so tell me procedure for this.
    Secondly in future may be I will share this database on server but now I am using this database only on my system with two users.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Did you bind SWITCHBOARD to Users table?

    Do you have code in the login form to open filtered SWITCHBOARD?

    If yesses then code in SWITCHBOARD Open event:
    If Me!strempname = "abc" Then Me.Command7.Visible = False
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    No I did not bind s.board with users table.
    how to bind?
    No I don't have any code in login form for filtered s.board.
    all the code in user form is as I mentioned in post no. 3

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Bind form by setting RecordSource property. Basic Access functionality for building forms. Access Help has guidance.

    If you want to try the described method, then follow instructions given for coding. Test, debug, fix errors, repeat. Refer to link at bottom of my post for debug techniques.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Ohh sorry I was forgot about binding.
    Now I binded switch board with user table.
    I changed the login code like this:
    'Close logon form and open splash screen


    DoCmd.OpenForm "SWITCHBOARD", , , "strempname='" & Me.strempname & "'"

    so login form will not close after login.
    I bound one text box on switchboard with user names.
    I put this code on switchboard open event:
    If Me!strempname = "abc" Then Me.Command7.Visible = False

    what I do now?
    Thanks

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why won't login form close? You show code in procedure to close the form.

    Is suggested code working? If so, then your issue is resolved. I don't know what you want to do beyond that.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    I remove this line from coding
    DoCmd.Close acForm, "logon", acSavePrompt
    bcoz as you said in post no.4
    Then code in any form can refer to the SWITCHBOARD (as long as it never closes) for criteria.
    I want to code on login form which will never close.

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Did you misread my statement?

    I said the SWITCHBOARD form should never close, not the Login form.

    If you want to do something different from my suggestion then explain what you want.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Ohh yes sorry I misread your statement.
    yes I did as you said but now the problem is the text box which I bound with user name on switchboard.
    if I login as xyz or abc there is always showing xyz and secondly command7 is also always visible.

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is strempname a field or control name on the login form? I can't tell from your code.

    What control on login form has the username? That is the control to reference in the code that opens SWITCHBOARD.

    Do you want to provide db for analysis? Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    OK thanks.
    tomorrow I will try myself if I didn't solve then I will provide db.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Enabling fields in form
    By Kivan in forum Programming
    Replies: 8
    Last Post: 08-22-2012, 03:44 AM
  2. Enabling and disabling fields
    By SgtSaunders69 in forum Programming
    Replies: 9
    Last Post: 12-27-2011, 06:11 PM
  3. Command button dis-enabling
    By Reaper in forum Forms
    Replies: 2
    Last Post: 11-23-2011, 10:51 AM
  4. Disabling and Enabling subforms
    By vt800c in forum Programming
    Replies: 3
    Last Post: 05-24-2011, 07:37 AM
  5. Enabling a control and moving to a new tab in vba
    By MuskokaMad in forum Programming
    Replies: 1
    Last Post: 03-14-2010, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums