By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,575 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,575 IT Pros & Developers. It's quick & easy.

save record using password protected cmd button

P: 49
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdManualUpdate_Click()
  2. Dim strPasswd
  4.     strPasswd = InputBox("Enter Password", "Restricted Form")
  6.     'Check to see if there is any entry made to input box, or if
  7.     'cancel button is pressed. If no entry made then exit sub.
  9.     If strPasswd = "" Or strPasswd = Empty Then
  10.         MsgBox "No Input Provided", vbInformation, "Required Data"
  11.         Exit Sub
  12.     End If
  14.     'If correct password is entered open Employees form
  15.     'If incorrect password entered give message and exit sub
  17.     If strPasswd = DLookup("PWD", "AdminLogin") Then
  18.         Form.SetFocus
  19.         DoCmd.Save
  20.         DoCmd.GoToRecord , , acNewRec
  22.     Else
  23.         MsgBox "Sorry, you do not have access to this form", _
  24.                vbOKOnly, "Important Information"
  25.         Exit Sub
  26.     End If
  27. End Sub
It will also throw the following error when it hits the DoCmd.GoToRecord:

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?
Jan 12 '15 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 1,107
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.)
Jan 12 '15 #2

Expert 100+
P: 1,107
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 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.
Jan 12 '15 #3

P: 49
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.
Mar 6 '15 #4

P: 208

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.
Mar 6 '15 #5

Post your reply

Sign in to post your reply or Sign up for a free account.