Prohibiting edits to data in a text box

M

mjg

This seems like it should be simple:

Using a form property sheet Access allows me to specify "Allow Edits",
"Allow Additions", and "Allow Deletions", but these pertain to entire
records. I can't figure out how to "Allow Additions" and not "Allow Edits"
to just one specific control on my form. If I use the "Lock" feature then
the user can't populate the field of a new record.

Any tips?

-mjg
 
B

Beetle

In the forms current event

If Me.NewRecord Then
Me.ControlName.Locked = False
Else
Me.ControlName.Locked = True
End If
 
M

mjg

Beetle - thanks for quick reply.

This solution works, but it's not ideal - here's why.
The very first field on my form is a Parcel ID number which is required.
Once that number is entered the first time, I would like it to be locked.
Here's the catch: there are a number of other fields on the form that, in
practice will be populated over the course of time. Some may be filled in
right away, when the Parcel ID number is first entered, some may be filled in
weeks later, and some may need to be edited several years later. The forms
current event affects all of these controls and I would like it to only
affect the first one (Parcel ID).

- mjg
 
D

Douglas J. Steele

But Beetle's suggestion is strictly locking a single control!

Based on what you've added, you'd probably want

If Me.NewRecord Then
Me.ParcelID.Locked = False
Else
If Len(Me.ParcelID & vbNullString) > 0 Then
Me.ParcelID.Locked = True
Else
Me.ParcelID.Locked = False
End If
End If

Even simpler is

Me.ParcelID.Locked = Not Me.NewRecord And (Len(Me.ParcelID & vbNullString) >
0)

Note that you'll likely want to introduce some means of unlocking the field
in case an error needs to be corrected.
 
M

mjg

You were right, Beetle's solution worked fine.

I'm new to VB and don't understand some of the code below
("Len...vbNullString") so I just stuck with the simple solution.

Thanks for your help,
-mjg
 

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