Results 1 to 14 of 14
  1. #1
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Question Password Protect Buttons on Forms

    Is it possible to set security on just a button on a form?


    Example, I have a switchboard, and I would like it so that if one was to click on a button on the switchboard it will require a password to function.

    If it is possible could someone show me an example of code for an onclick event?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if I were doing it, I would make a table of usernames with the permissions they have and the names of the buttons on the switchboard form. something like:
    Code:
    on click
    
       if dlookup("haspermissions", "switchboardbuttonpermissions", 
          "[username] = '" & environ(39) & "' AND [button] = '" & me.activecontrol.name & "'") = 0 then
          msgbox "sorry!  you can't access this function!
             exit sub
       else
          "msgbox "you're in!"
              MORE CODE FOR permitted USER.
       end if

  3. #3
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    So essentially, My switchboard has
    Option1-coordinator
    Option2-Lead
    Option3-Scheduler

    I should create a table with usernames, (should these be their windows logon usernames?)

    also in the table have the fields Coordinator, Lead and Scheduler (should I set these as yes/no values?)

    And the code would look like...

    Code:
    on click     
    if dlookup("haspermissions", "switchboardbuttonpermissions", 
    "[username] = '" & environ(39) & "' AND [option1,2or3] = '" & me.activecontrol.name & "'") = 0 then       
    msgbox "sorry!  you can't access this function!          
    exit sub    else       "msgbox "you're in!"           
    MORE CODE FOR permitted USER.    end if
    is this right?

    and how come my BBCode isn't working?

    Im trying to do this to get around having to really set any kind of end user security settings.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    the code isn't working because you forgot the "/" character in the closing tag.

    the usernames can be anything, it doesn't matter. only you know how you track your users. there's nothing wrong with storing windows UNs in a table, as far as I know, unless you're against it for personal reasons. the windows usernames might take a while to get because you have to have an exhaustive list of the ones that will be using your file before you could implement something like this, otherwise it would be useless.

    the only boolean field in the table should be "haspermissions". the table I was thinking of would generally look like this:

    *username
    *buttonname
    *haspermissions

    of course, if you have a lot of usernames, you could even create two tables with a one-to-many relationship...user table as PK and the rest of the info as the FK table, linked on username or autonumber ID. does this make sense?
    just giving you a starting point. It's open for consideration, based on what you think is best for your situation.

    btw, are you in Dallas? If so, I was wondering how good the job market is for teachers down there. I heard it was great...here in Iowa teachers don't make anything. They're losing them like crazy.

  5. #5
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Yeah that makes a lot of sense. Fortunately I dont have a whole lot of users who will be using the DB, Ill give it a shot.

    I'm in Alaska. Prudhoe Bay to be exact. I work up here and live in Oklahoma. From what I know about the school districts in both places, you would probably be no better off than you are now.

    So this option you have given me, this should work for distribution also right? I mean as far as multiple computer stations on the same network?

    Also, bear with me, I am learning code on the fly here, would the "haspermissions" field in the table be set as a y/n field?

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    yes. I said that in the previous post. that's the only boolean (y/n) field.

    as far as on a network is concerned, there can't be two users with the same username, can there? I would assume that would be a possibility because usernames are specific to computers and their operating systems. so running into a dup would be possible. in that case, you'd need to have a failsafe otherwise you'd not know who the person was for sure.

    you're in Alaska? I was browsing the forum tonight and I was checking my website log. the last one was someone went to that function page from this page so I assumed it was you. Guess not! Thank goodness too! If it was you, my scripts would not be obeying me! That would be BAD...

  7. #7
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Oops. Srry about that. I guess you did mention that.

    No there won't be users with the same username so thats good.

    It wouldnt suprise me if the network Im on is out of Dallas, it is a BP network. Alaska and Texas being full of oil and gas Im sure its a possibility.

    BTW thanks for helping me out in both forums, I see that you just responded to our other posts. Its like forum tag.
    I appreciate your help.

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    no problem. I'm jsut up studying for a master's degree program test. Talk about a lot of work. Just wait until I have to sit for the CPA test. That's a killer I hear nowadays, and plus they charge close to a thousand just to take it!

    thanks for the info too...I learned a little bit about the database I'm using for logs. Maybe it sources the networks? Interesting... If so, it's not as useful as I thought it was!

  9. #9
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Lol!

    Well good luck!

    I'm in the inspection industry. Just about all of the certifications I go after are about 1k a cert also but that's usually just for a 40 hour course. Then I have to pay the sitting fees for the test as well. Sucks! But every cert ends up paying for itself pretty soon after obtaining it.

    Thanks again for your continued support. As soon as I get a chance to put this info into practical use and find it working flawlessly I will mark the thread as solved. Should be sometime tonight.

  10. #10
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    I didn't think I was going to have issues with this but I am.
    Here's what I got.

    Table: UsernamesandPermissions

    (example)
    UserName ButtonName Permissions
    John Doe Option1 (checked as yes)

    the switchboard form name is "Switchboard"

    Would you mind showing me what the code should look like? I am doing something wrong for sure. But don't know what it is.

  11. #11
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Actually, I found a way to achieve exactly what Im looking for with a different code.

    Code:
    In ON CLICK event
    Dim PassWord As String
       PassWord = InputBox("Enter Password")
       If PassWord = "MYPassword" Then
          ' Open Form
          DoCmd.OpenForm "MYFormName"
          DoCmd.GoToRecord , , acNewRec
       Else
          MsgBox ("You're not authorized")
       End If
    Thanks for your help, got me started in the right direction. And once again, good luck on your studies.

  12. #12
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by Desstro View Post
    I didn't think I was going to have issues with this but I am.
    Here's what I got.

    Table: UsernamesandPermissions

    (example)
    UserName ButtonName Permissions
    John Doe Option1 (checked as yes)

    the switchboard form name is "Switchboard"

    Would you mind showing me what the code should look like? I am doing something wrong for sure. But don't know what it is.
    I'm tired right now, it's 330 in the morning, but here it is:
    Code:
    option1_click(cancel as integer)
    
    if dlookup("permissions", "usernamesandpermissions", 
           "[username] = '" & environ(39) & "' AND " & _
           "[buttonname] = '" & me.activecontrol.name & "'") == 0 then
        msgbox "Oops!  You don't have permissions!"
            exit sub
    else
        LET THEM ON THROUGH...
    end if
    <edit>
    forget the "==". sorry, that's a single, not a double. was thinking another lang.

  13. #13
    P.Malius is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    10
    Further to this... is there a way to stop the characters showing in the input box? So the characters would show as '*' rather than the actual letters?

  14. #14
    jcmullett is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    1
    Can anyone please tell me where I enter the code to the On Click event? I tried entering it as a code and it would not work. I tried setting up a module, still would not work. Have no idea how to approach this problem. Where do I enter that code? Help!!!! Need to restrict access to all the forms I setup but everything I tried has failed.

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

Similar Threads

  1. P/W Protect & Open Database Using VBA
    By DrGlenn in forum Programming
    Replies: 1
    Last Post: 08-06-2010, 08:08 PM
  2. Replies: 0
    Last Post: 07-08-2010, 11:22 PM
  3. readonly password protect
    By mlgehle in forum Security
    Replies: 1
    Last Post: 03-13-2010, 08:59 PM
  4. Password Protect Forms
    By Robert M in forum Programming
    Replies: 3
    Last Post: 01-15-2010, 01:50 PM
  5. Change from old password to new password
    By richy in forum Security
    Replies: 0
    Last Post: 11-17-2005, 05:05 AM

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