Results 1 to 14 of 14
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    strAccess

    Hi All, working with access 2003. I need to add a frmlogin form to an existingdatabase. I also want to restrict usersto a form based on their access level. I have a users table with the followingfields:
    strEmpName, strEmpPassword, strAccess. On form load of the form; I put:
    Code:
    Private Sub Form_Load()
    If strAccess <> "admin" And strAccess <> "sup" Then
    DoCmd.Close
    MsgBox "You do not have sufficient security to make changes in this form"
    End If
    End Sub
    When testing; I put myself as admin; it gives me the msgbox. Doesn’t give me access. What am I doing wrong?


    thanks



  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    its the logic of the 'And'.....

    strAccess can't have 2 values at the same time...

    break those into 2 separate if/then statements would be one approach to a fix....

    hope this helps

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Ok. Tried:

    Code:
    If strAccess <> "admin"  Then
    Still doesn't work. I wonder if the "strAccess" need declaring? I never had to before. But; just maybe?

    Help! Still does't work!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    How does this Form relate to the Table?

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    It doesn't. I want to use the values in tblUsers field strAccess to open the form

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    More info please. If the table that has the fields and values you need is not related to the Form, what exactly do you expect to happen?
    Perhaps you could tell us in plain English WHAT you want to occur, and what you have in place.
    What is the record source of the Form?

  7. #7
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ok. The database has a login form for users to get into the database. One they are in the database; they come to a switchboard with three buttons. Depending on their access level; which comes from the tblUsers which has the following fields: strName strPassword strAccess. The strAccess has user, sup or admin. I would like to have code behind the three buttons to have them access based on their level. I have the following code on the form load on each form the users have access to:

    Code:
    Private Sub Form_Load()
    If strAccess <> "admin" Then
       DoCmd.Close
       MsgBox "You do not have sufficient security to make changes in this form"
    End If
    End Sub
    The other buttons have the same code but with the different access levels; users, sup etc. I don't want them to have access to each other forms.
    I hope this helps you help me
    Thank you
    Last edited by June7; 03-06-2013 at 07:27 PM. Reason: fix code tag

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Where is strAccess declared and set? It must be declared in the object's module header in order to be available to any procedure in that object's code module. Then question is in what event to set the variable - form Load? Problem with these 'public/global' variables is that they lose value if code execution is interrupted. In my db I populate a textbox on a form that never closes (such as a main menu) and refer to the textbox in code.
    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
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ? I am not clear on how to proceed. A little guidance please

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    You did not answer question of how you declare and set the strAccess variable.

    I have described use of and issue with the global variable and also my preferred approach.

    Decide which approach 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.

  11. #11
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Sorry. On my main switchboard form the buttons are unbound. I vagley remember declaring the variable strAccess as string and doing a dlookup to the table. But I don't remember the rest of the code. I am interested in your preferance but I don't think the users would keep the form open?

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    In my project the users cannot close the main menu form. I disable the X close button on all forms. I also disable a lot of other features, such as the Navigation pane and the right click shortcut menu and function keys. I created a custom ribbon so users cannot get to development tools. The main menu form is fairly small and all other forms open on top of it.

    However, holding down the shift key when opening will override most of these settings so that's how I get in development mode. I trust my users not to mess with the design.

    Another alternative is to do the DLookup every time you need this info for conditional code. My Users table stores the users network login ID and their rights category. I use Environ("USERNAME") to retrieve the network login and do DLookup to get their rights. Users don't even see a login form unless they are brand new and no record is in Users table. This login will save record into Users table and then they never see the login again.
    Last edited by June7; 03-07-2013 at 10:18 PM.
    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
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Ok. I have about 50-60 users that would uses this database at any given time. To use Environ(username); wouldnt work with multiple users right. I can not remember the code I used a few years back trying to get this to work. All the users are able to access one button but the other two need only access by sups and admins!

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Environ("USERNAME") - yes, type it exactly like that quotes and all - will work with multiple users. At most, I have a dozen users.
    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.

Please reply to this thread with any new information or opinions.

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