Hi, Im fairly new in the Access world. I would like to know how I can prevent users from changing data entered into a specific field of a record. Once I have completed the data Entry they should be able to see the information but not be able to change it.
How to lock a field in a record or make it read only
Collapse
X
-
Originally posted by eimbertHi, Im fairly new in the Access world. I would like to know how I can prevent users from changing data entered into a specific field of a record. Once I have completed the data Entry they should be able to see the information but not be able to change it.
Code:Private Sub Form_Current() If Not Me.NewRecord Then 'Lock YourControl for each record. Me!YourControl.Locked = True Else Me!YourControl.Locked = False End If End Sub
-
Hi
Originally posted by puppydogbuddyHere is one way, assuming that you are using a bound form for data entry:
Code:Private Sub Form_Current() If Not Me.NewRecord Then 'Lock YourControl for each record. Me!YourControl.Locked = True Else Me!YourControl.Locked = False End If End Sub
Code:Private Sub Form_Current() If Me.NewRecord Then Me.AllowEdits = True Else Me.AllowEdits = False End If End Sub
Me.AllowDeletio ns= ....
if you want to prevent record deletion also.
MTBComment
-
Thanks for the advise. I have used this code to lock all fields in current form. Once the first record is created the code doesn't allow any editing or deleting. The problem I have now is how to make changes to that record at a later time.
Any Additional advise will be highly appreciated
1. Private Sub Form_Current()
2. If Me.NewRecord Then
3. Me.AllowAdditio ns = True
4. Me.AllowDeletio ns = True
5. Me.AllowEdits = True
6. Else
7. Me.AllowAdditio ns = True
8. Me.AllowDeletio ns = False
9. Me.AllowEdits = False
10. End IfComment
-
Originally posted by eimbertThanks for the advise. I have used this code to lock all fields in current form. Once the first record is created the code doesn't allow any editing or deleting. The problem I have now is how to make changes to that record at a later time.
Any Additional advise will be highly appreciated
1. Private Sub Form_Current()
2. If Me.NewRecord Then
3. Me.AllowAdditio ns = True
4. Me.AllowDeletio ns = True
5. Me.AllowEdits = True
6. Else
7. Me.AllowAdditio ns = True
8. Me.AllowDeletio ns = False
9. Me.AllowEdits = False
10. End If
Define 'that record' and
Define under what circumstances you want the record to be edited.
M TBComment
-
Originally posted by MikeTheBikeTwo things
Define 'that record' and
Define under what circumstances you want the record to be edited.
M TBComment
-
Originally posted by eimbertIm very new at access and I really don't know much of VBA programming. So Im just looking for an easy way to control the data entry process. Can I create a Command Button and lets say we call it (Edit) and from there you could work in edit mode for that form? A (delete) Button etc. I was thinking about running These command buttons from a Main Form Menu. I just dont know the language to make this work correctly. If you have any better suggestions I would highly appreciate it.
Code:Sub cmdEdit_Click On Error GoTo Err_cmdEdit_Click Me.AllowEdits = True Exit_cmdEdit_Click: Exit Sub Err_cmdEdit_Click: MsgBox Err.Description Resume Exit_cmdEdit_Click End sub
cmdDeleteButton
Code:Private Sub cmdDelete_Click() On Error GoTo Err_cmdDelete_Click If MsgBox("Do you want to delete record?", vbYesNo + vbQuestion) = vbNo Then Exit Sub RunCommand acCmdDeleteRecord Exit_cmdDelete_Click: Exit Sub Err_cmdDelete_Click: MsgBox Err.Description Resume Exit_cmdDelete_Click End Sub
There are options for deleting records etc. (although the code generated will be different form above).
MTBComment
-
Thanks for your patience and help . I used the code for editing you gave me. I created a Command button on the actual form the data entry is being done on and named it (Edit). I have used the code below to lock the form , and to be able to edit it. When the form is opened all the fields are locked(good) but when I click on the cmdEdit button the fields remain locked. I have saved and closed the form various times but records are still locked. I haven't done the (delete)button until I know that the code does work. Should I put the command (edit) button somewhere other than the data entry form for this code to work?
Thank You
Private Sub Form_Current()
If Me.NewRecord Then
Me.AllowEdits = True
Me.AllowDeletio ns = True
Else
Me.AllowEdits = False
Me.AllowDeletio ns = False
End If
End Sub
Private Sub cmdEdit_Click()
On Error GoTo Err_cmdEdit_Cli ck
Me.AllowEdits = True
Exit_cmdEdit_Cl ick:
Exit Sub
Err_cmdEdit_Cli ck:
MsgBox Err.Description
Resume Exit_cmdEdit_Cl ick
End SubComment
-
Originally posted by eimbertI have also used the Code for deleting a record and I get an error " The command or action Deleterecord isn't available now.
Me.AllowDeletio ns = True
RunCommand acCmdDeleteReco rd
Me.AllowDeletio ns = False
in the delete code.
for now, I do not know why the edit doesn'twork, it does for me.
I will think about it over the week end, but I am not sure about
Should I put the command (edit) button somewhere other than the data entry form for this code to work?
MTBComment
Comment