Locking a form

S

sgtschultz

I have a form to enter data for service calls. Is there a way to
automatically lock the data when I start a new record so the information I
entered on the previous record can't be altered/deleted? Thanks in advance
for the help

-Josh-
 
E

Elmtree via AccessMonster.com

When I create a form, I generally put 2 buttons on the bottom of my form. One
to Close the other to Add additional records.

Here is the code I use to make them work. May be an easier way to do it, but
it works for me.
----
...................................................To Close...................
...................................
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click

DoCmd.Close

Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub

..............................................To Add Additional Records.......
.....................................................
Private Sub Command25_Click()
On Error GoTo Err_Command25_Click

Dim stDocName As String
Dim stLinkCriteria As String

DoCmd.Close
stDocName = "ENTER YOUR FORM NAME HERE............."
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command25_Click:
Exit Sub

Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click

End Sub

----
 
B

Brian

You can set the DataEntry property to True. This will never display old
records when opening the form and will allow users to enter data but not
change old records. If it is a Continuous form, records in the current
session will continue to be displayed but cannot be changed after entry.
Every time the form is opened, it will show no prior records.

If you also want to provide some way to edit the data or view old records,
you will need to make a different form or have some settings that allow
certain users to open it with DataEntry=False.
 
B

Brian

I misspoke in my first e-mail a little. In a continuous form, prior records
can still be edited within the current session (not an issue if you are using
Single Form). You may need to also set AllowEdits = False in the form
properties to disallow editing of prior records in the same session.
 
D

Dirk Goldgar

sgtschultz said:
I have a form to enter data for service calls. Is there a way to
automatically lock the data when I start a new record so the information I
entered on the previous record can't be altered/deleted? Thanks in advance
for the help

-Josh-


Yes, but you're probably going to need a way to unlock them on those
occasions when you really do need to edit a previous call record.

To set things so that existing records can't be edited, use code in the
form's Current event like this:

'----- start of example code -----
Private Sub Form_Current()

If Me.NewRecord Then
Me.AllowEdits = True
Me.AllowDeletions = True
Else
Me.AllowEdits = False
Me.AllowDeletions = False
End If

End Sub
'----- end of example code -----

You might have a command button to unlock the a record:

'----- start of code for button -----
Private Sub cmdUnlock_Click()

Me.AllowEdits = True
Me.AllowDeletions = True

End Sub
'----- end of code for button -----

Note that setting the form's AllowEdits property to False will prevent you
from modifying *unbound* controls on the form as well, so you can't use (for
example) combo boxes for navigation. If that's a problem on this form,
there are ways around it that involve more complicated code than I posted
above.
 
Top