Database password form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have an access2003 database that is only going to have 1 user. i want the
user to put a password in before the main switchboard is opened. i know i can
go to tools - security - set database password, which works fine.
Is there a way that from a cmd button i can open a form where the user can
change the default passord i set, to a password of there choice??

How easy is it to retrieve this password if user forgets it??

Thanks to anyone who looks into this
 
the user has to actually "unset" the database password, and then set it
again, to whatever value s/he wants. i use the following code in a public
module, calling it from a command button's Click event. AFAIK, it will also
work if you use it in a form's module (just change the word "Public" to
"Private"), as

Public Sub isSetPassword()

On Error GoTo Password_Err

Dim str As String
str = "Set Database Password..."

CommandBars("Menu
Bar").Controls("Tools").Controls("Security").Controls(str).accDoDefaultActio
n

' the above two lines actually go all on one line.
' they're just "wrapped" in the text of the NG post.
' so just restore to one line, making sure there is
' no space between Controls and (str)

Password_End:
Exit Sub

Password_Err:
If Err.Number = 5 Then
str = "Unset Database Password..."
Resume
Else
MsgBox Err.Number & " " & Err.Description
Resume Password_End
End If

End Sub

note that the Set/Unset Password dialog will not open unless the database
has been opened exclusively. you may or may not get an error message when
the db was *not* opened exclusively.

hth
 
thanks for reply Tina,

what do you mean by open the database exclusively? whats the different open
modes??
 
open Access. from the menu bar, click File | Open, which opens the
navigation dialog box. navigate to the database file, then STOP. the Open
button has a down arrow at the right side. click that to see the Open
options, including Open Exclusive.

hth
 
Tina, this is the code im using

Private Sub Command1_Click()

Dim str As String
str = "Set Database Password..."


CommandBars("MenuBar").Controls("Tools").Controls("Security").Controls(str).accDoDefaultAction

' the above two lines actually go all on one line.
' they're just "wrapped" in the text of the NG post.
' so just restore to one line, making sure there is
' no space between Controls and (str)

Password_End:
Exit Sub

Password_Err:
If Err.Number = 5 Then
str = "Unset Database Password..."
Resume
Else
MsgBox Err.Number & " " & Err.Description
Resume Password_End
End If

End Sub

When i click my cmd buton i get a runtime error 5 invalid procedure call or
arguments, any ideas on how to resolve this please
 
that's the very error that the error handler is set up to take care of. when
you copy/pasted the code i posted, you omitted the first line *inside* the
procedure, as

On Error GoTo Password_Err

paste that line into your procedure *directly below* the line

Private Sub Command1_Click()

hth
 
thanks for the response tina,

when the full code was copied in to my on click event and i pressed the cmd
button, the code seemed to hung up, by this i mean i got the egg timer and
access stopped responding, i then started to remove some code to see what was
causing this error and found out it was

On Error GoTo Password_Err

therefore with this line of code, access stops resonding and i have to
presscontrol,alt,delete to get out.

any ideas why??
 
well, the GoTo code is necessary to handle the "5" error. there may be a way
to check whether a password is already set on the database *before* the
CommandBars line runs - but i don't know how.

the code runs fine in my database, which is an Access 2000 file format,
built in Access 2003. it's possible the problem has to do with the version
of Access you're using. since i don't have anything helpful to offer,
suggest you post the *complete* code i gave you in a new thread - perhaps in
microsoft.public.access.modulesdaovba newsgroup. explain the problem you're
having with the code "hanging", and be sure to include what version of
Access you're building the db in. maybe somebody else will able to help you
get it running, or at least tell you why it won't run.

hth
 
many thanks for your efforts

tina said:
well, the GoTo code is necessary to handle the "5" error. there may be a way
to check whether a password is already set on the database *before* the
CommandBars line runs - but i don't know how.

the code runs fine in my database, which is an Access 2000 file format,
built in Access 2003. it's possible the problem has to do with the version
of Access you're using. since i don't have anything helpful to offer,
suggest you post the *complete* code i gave you in a new thread - perhaps in
microsoft.public.access.modulesdaovba newsgroup. explain the problem you're
having with the code "hanging", and be sure to include what version of
Access you're building the db in. maybe somebody else will able to help you
get it running, or at least tell you why it won't run.

hth
 
Back
Top