Making fields uneditable

T

Tony Williams

I want to add a table to my database which has 3 fields, Date, Time, Action
Log (I'll use field names that don't conflict with Access reserved names) I
will then create a datasheet form with these fields as the source for 3
controls. I want the Date and Time to be system generated as the user starts
to complete the form. The Action log will be a memo filed. I can get this
far but I want the fields to be un-editable once they have been input. I am
trying to create an Action Log table for a user to complete as they perform
an action, possibly on a daily but infrequent basis, which will be a record
of their actions.
Can anyone help with how I make the data that is completed un-editable?
Thanks
Tony
 
G

Guest

Hi Tony

In your form design set the fields as locked (data tab of field properties)

Then go to the properties of the form - event tab - and for the On Current
event enter the following event procedure...

Private Sub Form_Current()
If Me.NewRecord Then
Me.FieldName.Locked = False
Else
Me.FieldName.Locked = True
End If
End Sub

Substitute in your actual field names.

hth

Andy Hull
 
A

Allen Browne

Use the Current event of the form.

Loop through the Controls collection of the form. Set the Locked property
for the controls that are bound to fields (not expressions, nor unbound, nor
controls like lines and command buttons that have no Control Source) based
on whether the control IsNull().
 
T

Tony Williams

Thanks guys but I'm slightly confused as you both seem to be suggesting
something slightly different. In your example Andy you have shown only one
field how do I add the other two fields? Is this what Allen means by looping
through the fields? If so how would I code that? Also Allen, you mentioned
not using expressions, I had intended the Date and Time fields to be the
system date and time, this wouldn't preclude me from setting the locked
property of these two fields would it?
Sorry for this, this is new to me.
Thanks
Tony
 
A

Allen Browne

If a control is bound to an expression, its Control Source starts with "=".
Example:
=[Quantity] * [PriceEach]
There is no point locking these controls: they are not editable anyway.

Here's an example of code that loops through all the controls on the form,
identifies those that have a Control Source, eliminates those that are
unbound or bound to expressions, eliminates the autonumber, and also allows
you to specify controls that should not be locked/unlocked:
http://allenbrowne.com/ser-56.html

That code just locks/unlocks all the bound controls, so you will need to
modify using IsNull(), and run it in Form_Current.
 
T

Tony Williams

Thanks Allen, I think (????) I can follow that. I'll have a go and come back
in a few days with any problems under a new post if that's OK?
Cheers
Tony
Allen Browne said:
If a control is bound to an expression, its Control Source starts with
"=". Example:
=[Quantity] * [PriceEach]
There is no point locking these controls: they are not editable anyway.

Here's an example of code that loops through all the controls on the form,
identifies those that have a Control Source, eliminates those that are
unbound or bound to expressions, eliminates the autonumber, and also
allows you to specify controls that should not be locked/unlocked:
http://allenbrowne.com/ser-56.html

That code just locks/unlocks all the bound controls, so you will need to
modify using IsNull(), and run it in Form_Current.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Tony Williams said:
Thanks guys but I'm slightly confused as you both seem to be suggesting
something slightly different. In your example Andy you have shown only
one field how do I add the other two fields? Is this what Allen means by
looping through the fields? If so how would I code that? Also Allen, you
mentioned not using expressions, I had intended the Date and Time fields
to be the system date and time, this wouldn't preclude me from setting
the locked property of these two fields would it?
Sorry for this, this is new to me.
Thanks
Tony
 

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