save record using password protected cmd button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sooli
    New Member
    • Sep 2014
    • 49

    save record using password protected cmd button

    I am trying to make available a way to save "new" old data to the database. If someone forgets to enter their verification, i need a way for the boss to be able to enter that information at a later time. The database is set to be realtime, so the fields on the form are controlled by the user clicking a save button which automatically fills the date field and they cannot adjust the date. But when someone forgets to verify their work, we have holes that need to be filled in... right now i just go into the corresponding table and add it, but i have 60+ tables and its a little tedious for the "boss" to do. I want a button on each form that he can use, that allows him to update, but no one else - via his password.

    here's the catch - since I have 60+ tables, I want the button to ask for his password, and verify it with the admin table which has his password in it, if the password matches save the record and open a new record.

    I thought I had it, it seems to save it, but when i step thru to make sure its working this error comes up when it hits DoCmd.Save:

    Run-time error '2487':

    The Object Type argument for the action or method is blank or invalid.

    here's my code
    Code:
    Private Sub cmdManualUpdate_Click()
    Dim strPasswd
    
        strPasswd = InputBox("Enter Password", "Restricted Form")
    
        'Check to see if there is any entry made to input box, or if
        'cancel button is pressed. If no entry made then exit sub.
    
        If strPasswd = "" Or strPasswd = Empty Then
            MsgBox "No Input Provided", vbInformation, "Required Data"
            Exit Sub
        End If
    
        'If correct password is entered open Employees form
        'If incorrect password entered give message and exit sub
    
        If strPasswd = DLookup("PWD", "AdminLogin") Then
            Form.SetFocus
            DoCmd.Save
            DoCmd.GoToRecord , , acNewRec
            
        Else
            MsgBox "Sorry, you do not have access to this form", _
                   vbOKOnly, "Important Information"
            Exit Sub
        End If
    End Sub
    It will also throw the following error when it hits the DoCmd.GoToRecor d:

    Run-time error '2046'
    The command or action 'GoToRecord' isn't avaialbel now.

    yet if I don't have the break points it actually goes to a new record like i wanted it to. I just don't understand why its throwing errors during the step thru, and seemingly does what i want it to.


    I also noticed... if i don't use the correct capitalization, it still lets it go thru, if I use the wrong word it is fine... is there a way to make it be case dependent?
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    My guess is it's the Setfocus during Debug throwing an error, Access can't handle it. It's not you, it's Access. Access has trouble updating/using the UI while in Debug. Visual Studio has this trouble as well. Either step over that during debugging or put your breakpoint on line 19.

    You'll want to use StrComp to consider case when comparing strings. (You can thank Rabbit for that link.)
    Last edited by jforbes; Jan 12 '15, 01:45 PM. Reason: clarification

    Comment

    • jforbes
      Recognized Expert Top Contributor
      • Aug 2014
      • 1107

      #3
      There is another way to approach locking down button on a Form that might be a lot easier for both you and your Boss. You could have the Button (or any other control on the Form) enabled or disabled based on what User is logged into the Windows computer.

      You can use the function provided at http://access.mvps.org/access/api/api0008.htm to get the currently logged in User. Then on either the OnCurrent or OnLoad of the Form enable/disable controls based on user. You could even take it even further and compare it against a user table if you want.

      The end result would be that the prompt for password as well as all the messages would go away and the button would only be enabled for valid users.

      Comment

      • sooli
        New Member
        • Sep 2014
        • 49

        #4
        I made a work around that turned out to be golden! I have the table's appear in datasheet mode at the bottom of the form if the correct password is entered as a result of a button click. This sub-form is set to not visible until the password is entered, so no one can see it except for the admin & the Boss loved it!

        Boss didn't want the users to have to log in to the database... no idea why...but that is what he wanted so that is what he got... I know this limits my ability to lock things down...and I explained that to him. He is under the impression I believe, that folks won't know enough about Access to do anything harmful... so password/protecting wasn't necessary for the average user.

        Comment

        • Brilstern
          New Member
          • Dec 2011
          • 208

          #5
          sooli,

          While yes, your boss is somewhat right, it doesn't keep the average user from learning how to bypass security controls. A quick search in Google can be used to bypass even the more complex security controls.I would strongly suggest you browse Rabbit's article on Database Security and twinnyfo's article on user permissions, and the articles linked in twinnyfo's as well. Although I understand certain situations require less or more security, being informed nonetheless is a the only way to be one step ahead. Hope you take some time to browse their expertise.

          Comment

          Working...