AllowEdits =False -- It can't be this difficult!

I

Ian Smith

Intuitively, one might expect that setting a form's
AllowEdits property false would prevent the user from
changing the contents of the form's underlying record.
Unfortunately, that's not the case--It prevents you from
altering the contents of any the form's controls, even the
unbound controls that are controlling the behavior of the
form. I can't even click a tab to move to another page,
for gosh sakes! And the Edit button that would set
AllowEdits true again is also disabled!

That being the case, if I want my form read-only, but want
it to behave properly, I appears must cycle through all of
it's controls to disable bound controls while leaving
unbound controls alone. And whenever I encounter a
subform, I must drop down into it and do the same thing
there. And to make it all worse, I get errors when I try
to look at a control's ControlSource property to deterlime
if it is unbound.

Please tell me I am on the wrong track here. Tell me
there's a simple way to accomplish this.
 
B

Bruce M. Thompson

Intuitively, one might expect that setting a form's
AllowEdits property false would prevent the user from
changing the contents of the form's underlying record.
Unfortunately, that's not the case--It prevents you from
altering the contents of any the form's controls, even the
unbound controls that are controlling the behavior of the
form.

Yes, that is typical behavior.
I can't even click a tab to move to another page,
for gosh sakes! And the Edit button that would set
AllowEdits true again is also disabled!

That is not true.
That being the case, if I want my form read-only, but want
it to behave properly, I appears must cycle through all of
it's controls to disable bound controls while leaving
unbound controls alone.

Locking the appropriate controls is one way of doing it. I usually set the "Tag"
property of those controls that I want to protect to a value such as "lock" and
then write a short snippet of code to cycle throught he controls collection to
set the locked property as needed.
And whenever I encounter a
subform, I must drop down into it and do the same thing
there.

You can just lock the subform control. It's unlikely that you have any unbound
controls on that.
And to make it all worse, I get errors when I try
to look at a control's ControlSource property to deterlime
if it is unbound.

See my comments on locking, above.
Please tell me I am on the wrong track here. Tell me
there's a simple way to accomplish this.

Have you tried setting the "Recordset Type" property to "Snapshot"?
 
A

Allen Browne

AllowEdits does prevent changes to all controls (bound and unbound).

You could use a command button (not a toggle button) to toggle the
AllowEdits state of the form, but that won't solve the issue of the unbound
controls, so setting the Locked property is probably what you need.

Don't forget to:
- save any edits before locking the controls or turning off AllowEdits;
- toggle the form's AllowDeletions as well.

If the ControlType is acSubform, then yes, you do need to run your code
recursively for the embeded subforms as well.

Regarding the Control Source question, a control is bound if:
a) it has a ControlSource property, and
b) the ControlSource is not blank.
The ContolSource starts with "=" if the control is bound to an expression.

You cannot tell from the ControlType if it has a ControlSource, e.g unbound
option buttons do, but option buttons in a group to not. Here is a very
simple wrapper to determine if an object has a property:

Public Function HasProperty(obj As Object, strPropName As String) As Boolean
Dim varDummy As Variant
On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
 

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