Locking form after data entry

petehk

Registered User.
Local time
Today, 19:46
Joined
Oct 28, 2004
Messages
19
Hi ...... again. Does anyone out there know of a way that i could add a button to a form that when activated would lock all data on that record so that users are unable to edit the data after it has been confirmed? Thanks for your time.
 
Try pasting the code below either on Form_Current or Command Button.
It will lock the fields after it been typed and/or leave the blank fields open for data entry.

Dim Ctl As Control 'create a variable for the forms controls
Dim Frm As Form ' create a variable for the form

Set Frm = Me ' Sets the variable to the current form

For Each Ctl In Frm.Controls

On Error Resume Next

If Ctl <> 0 Or Ctl <> "" Then

Ctl.Locked = True ' Lock the control so the user can't change the data

Else

Ctl.Locked = False ' Otherwise unlock the control

End If

Next Ctl ' Moves onto the next control

Set Frm = Nothing ' Empty the Frm variable - good practice

hth,

Michael
 
Thanks for the thought. However the user needs to be able to edit the data up until the point where they confirm the data. I have set up different user levels and ideally all users would be able to confirm an order that they have placed using one button, and admin users would have another button to be able to unlock the record. The user level issue i am ok to sort out but i don't know if it is possible to attach any code to the buttons to do what i require. Back to you guys, thanks.
 
Add a DateConfirmed field to your table.

Have it bound to a textbox on your form. Set this as not visible.

On the form's Current event:

Code:
Private Sub Form_Current()
    Me.AllowEdits = Not IsDate(Me.txtDateConfirmed)
End Sub

When you ask the user if they would like to confirm this (so that they can't edit it again) then set the DateConfirmed field to Now().
 
Sorry if i sounded like a dumbass with my last posted reply. Have looked at what you said originally and have set the code up on the button as follows:

Private Sub ConfirmPRAF_Click()
On Error GoTo Err_ConfirmPRAF_Click

Dim Ctl As Control 'create a variable for the forms controls
Dim Frm As Form ' create a variable for the form

Set Frm = Me ' Sets the variable to the current form

For Each Ctl In Frm.Controls

On Error Resume Next

If Ctl <> 0 Or Ctl <> "" Then

Ctl.Locked = True ' Lock the control so the user can't change the data

Else

Ctl.Locked = False ' Otherwise unlock the control

End If

Next Ctl ' Moves onto the next control

Set Frm = Nothing ' Empty the Frm variable - good practice

Exit_ConfirmPRAF_Click:
Exit Sub

Err_ConfirmPRAF_Click:
MsgBox Err.Description
Resume Exit_ConfirmPRAF_Click

End Sub


Have also created a button with reversed true and false values so that it is possible to unlock the form, (although this is restricted for admin level users) and it works a treat. Genius mate, thanks very much for your help!
 

Users who are viewing this thread

Back
Top Bottom