Record Lock

G

Guest

I have a form that I set the property, no edits, no delete, and no additions.
I also created a command button to allow the above when clicked. How can I
have this command button check a field (which I would liike to enter a
password, so not just anyone can press the button) if the record is locked?
If the field equals aaa then unlock record.

Thanks.
 
S

strive4peace

on the form current event:

me.AllowEdits = false

on the code for the command button, if the password is right -->
me.AllowEdits = true

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

That's my problem. How can I enter a value in the field (the one the command
button will check) if it locked?

Thanks.
 
S

strive4peace

instead of using a form control, use InputBox in your code...

put this on a command button

'~~~~~~~~~~~~`
dim mPassword as string

mPassword = InputBox("Enter the password")

if len(trim(mPassword)) = 0 then
exit sub
end if

if mPassword = "aaa" then
me.AllowEdits = true
end if

'~~~~~~~~~~~~`

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

That works great. How can I make that input box be in a password(*****)
format? Also, if they enter the wrong password, I would like it to say,
"wrong password, try again"

Thanks for your help.
 
S

strive4peace

yes, you can, but you cannot use inputbox, you must use a form...

make an unbound form:
Name --> usys_pw
Caption --> Enter Password
RecordSelectors --> No
NavigationButtons --> No
DividingLines --> No
AutoResize --> Yes
AutoCenter --> yes
Popup --> yes
Modal --> yes

controls:

textbox -->
Name --> EnterP
InputMask --> Password

Label_Prompt -->
Caption: Enter Password

code behind form:

'~~~~~~~~~~~

Private Sub EnterP_AfterUpdate()
SetRight (Me.EnterP)
DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
If Len(Nz(Me.OpenArgs)) = 0 Then
Me.Label_Prompt.Caption = "Enter Password"
Else
Me.Label_Prompt.Caption = Me.OpenArgs
End If
End Sub

Private Sub Form_Open(Cancel As Integer)
SetPW
End Sub

'~~~~~~~~~~~

when you want to use it:

'~~~~~~~~~~~
DoCmd.OpenForm "usys_pw", , , , , acDialog, _
"Enter Password to Edit"

If Not GetPW() Then
msgbox "You may not edit the record", , "Incorrect password"

'if this is on the Open event of a form
Cancel = True

Exit Sub
End If
'~~~~~~~~~~~

"Enter Password to Edit" --> or whatever you want the prompt be be if
other then "Enter Password"

in a general module:

'~~~~~~~~~~~

Dim gBooPW As Boolean


Function SetPW()
gBooPW = False
End Function

Function GetPW() As Boolean
GetPW = gBooPW
End Function

Function SetRight(pPW) As Boolean
gBooPW = IIf(Nz(pPW) = "yourpassword", True, False)
End Function

ie: "yourpassword" -- "aaa"

'~~~~~~~~~~~

note: I prefaced the formname with "usys" (user system -- like Msys --
Microsoft system) because it will only display if system objects are
checked under Tools, Options, View tab -- which, usually, they aren't


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
S

strive4peace

es, you can, but you cannot use inputbox, you must use a form...

make an unbound form:
Name --> usys_pw
Caption --> Enter Password
RecordSelectors --> No
NavigationButtons --> No
DividingLines --> No
AutoResize --> Yes
AutoCenter --> yes
Popup --> yes
Modal --> yes

controls:

textbox -->
Name --> EnterP
InputMask --> Password

Label_Prompt -->
Caption: Enter Password

code behind form:

'~~~~~~~~~~~

Private Sub EnterP_AfterUpdate()
SetRight (Me.EnterP)
DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
If Len(Nz(Me.OpenArgs)) = 0 Then
Me.Label_Prompt.Caption = "Enter Password"
Else
Me.Label_Prompt.Caption = Me.OpenArgs
End If
End Sub

Private Sub Form_Open(Cancel As Integer)
SetPW
End Sub

'~~~~~~~~~~~

when you want to use it:

'~~~~~~~~~~~
DoCmd.OpenForm "usys_pw", , , , , acDialog, _
"Enter Password to Edit"

If Not GetPW() Then
msgbox "You may not edit the record", , "Incorrect password"

'if this is on the Open event of a form
Cancel = True

Exit Sub
End If
'~~~~~~~~~~~

"Enter Password to Edit" --> or whatever you want the prompt be be if
other then "Enter Password"

in a general module:

'~~~~~~~~~~~

Dim gBooPW As Boolean


Function SetPW()
gBooPW = False
End Function

Function GetPW() As Boolean
GetPW = gBooPW
End Function

Function SetRight(pPW) As Boolean
gBooPW = IIf(Nz(pPW) = "yourpassword", True, False)
End Function

ie: "yourpassword" -- "aaa"

'~~~~~~~~~~~

note: I prefaced the formname with "usys" (user system -- like Msys --
Microsoft system) because it will only display if system objects are
checked under Tools, Options, View tab -- which, usually, they aren't


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top