简体   繁体   中英

Is it possible to add records into Ms Access Form, while some fields are locked?

In my Ms Access form - I have a few locked fields. So, that users won't be able to change existing information. But they might still needed to add a new records into the Form.

Is it possible to be able to add a new records, without changing or removing an existing ones?

Thanks, as always!

Define an On Current event on form level. Like

Private Sub Form_Current()

If Me.NewRecord Then
Me.txtField1.Enabled = True
Me.txtField2.Enabled = True

Else
Me.txtField1.Enabled = False
Me.txtField2.Enabled = False

End If

End Sub

Replace txtField1 and txtField2 with the names of your form fields.

If you want to be able to add new records and keep some form fields locked, you have to set the Locked property on the data tab only for those fields. You can do that in design mode, or you can do it via VBA code on form load.

See https://access-programmers.co.uk/forums/showthread.php?t=180359 for examples.

Your last comment explains things a little better, I believe what you're after is possible (assuming I have the right idea). There are many ways to go about doing what you suggest, but without more specifics it becomes harder to guide you. That being said, terminology you're looking for in this question is something along the lines of "Lock fields when the Current Record is not a New Record".

This may partially solve your problem, you can probably figure it out from there:

Within the form itself, go to the Property Sheet and Select Data . Within the Data Tab change Allow Edits to No .

This will allow only New Records to be added to your table through your form, which appears to be your end-goal.

(Of course, you'll need to remove any locks on the text boxes that still remain to add any new records)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM