Can you code around "Me.AllowEdits = False" for individual control

G

Guest

I've used "Me.AllowEdits = false" (no parens) in the on_current event of my
form. However, users need to be able to "edit" an option button on the form
(which is used to hide/display a subform and resize the form accordingly).

How can I code my way around that "me.allowedits = false" to allow one
option button to be selected or unselected within the form?

Thanks,
CW
 
J

JNLake

Use "me.allowedits = true"

Then set the "Locked" property of every other control to true

~J
 
G

Guest

Thanks J.

I sort of thought about that. Well, I thought about making all other
controls not "enabled". Maybe the lock will come across better.

Thanks for the reply,
CW
 
G

Guest

I usually get ahead of myself when I reply too quickly....

I might be able to work with that idea, but the whole point of adding the
me.allowedits = false is to utilize an "edit" button on the form to prevent
accidental data entry/deletion.

Unless there's a programatic way to change all those other controls back to
"unlocked" using the on_click event of the "edit" button, I'm just trading
one problem for another.

I'll have to think about it. I'm new to vba and am just learning both
syntax AND capability.

Thanks again,
CW
 
G

Graham Mandeno

Hi CW

This whole problem would not arise if AllowEdits applied only to bound
controls. It makes no sense to have it affect unbound controls.

However, we are stuck with it, so the workaround is to lock/unlock certain
controls in code, depending on the value of their Tag property. Something
like this:

Private Function LockControls(fLock as Boolean)
Dim ctl as Control
For Each ctl in Me.Controls
If ctl.Tag = "L" Then
ctl.Locked = fLock
ctl.Enabled = Not fLock
End If
Next ctl
End Function

To lock the controls:
Call LockControls(True)
.... and False to unlock

For each control, you want to be affected, set the Tag property to "L".
 
G

Guest

Thanks Graham,

I must be learning something because I was thinking, prior to reading your
post, that it SHOULD (but didn't) matter that the option button to hide/show
the subform was an unbound control.

I'll give the "lock/unlock" thing another try. Thanks for the code, too.

When you say "tag", is that like a smart tag or does it have some other
meaning in your post?

Thanks again,
CW

Graham Mandeno said:
Hi CW

This whole problem would not arise if AllowEdits applied only to bound
controls. It makes no sense to have it affect unbound controls.

However, we are stuck with it, so the workaround is to lock/unlock certain
controls in code, depending on the value of their Tag property. Something
like this:

Private Function LockControls(fLock as Boolean)
Dim ctl as Control
For Each ctl in Me.Controls
If ctl.Tag = "L" Then
ctl.Locked = fLock
ctl.Enabled = Not fLock
End If
Next ctl
End Function

To lock the controls:
Call LockControls(True)
.... and False to unlock

For each control, you want to be affected, set the Tag property to "L".
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Cheese_whiz said:
I usually get ahead of myself when I reply too quickly....

I might be able to work with that idea, but the whole point of adding the
me.allowedits = false is to utilize an "edit" button on the form to
prevent
accidental data entry/deletion.

Unless there's a programatic way to change all those other controls back
to
"unlocked" using the on_click event of the "edit" button, I'm just trading
one problem for another.

I'll have to think about it. I'm new to vba and am just learning both
syntax AND capability.

Thanks again,
CW
 
D

Dirk Goldgar

Cheese_whiz said:
When you say "tag", is that like a smart tag or does it have some
other meaning in your post?

Every Access control has a Tag property, which you can use entirely for
your own purposes and set to any value you like. You'll find it on the
Other tab of the control's property sheet in design view.
 
G

Guest

Thanks DG. Don't know how I missed that...

CW

Dirk Goldgar said:
Every Access control has a Tag property, which you can use entirely for
your own purposes and set to any value you like. You'll find it on the
Other tab of the control's property sheet in design view.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
G

Guest

Graham,

I tried that method and, though I'm sure it works, I had some trouble
getting it to work for me. I wasn't even really sure where exactly I was
suppose to put the function. I ended up selecting the "form" object and
clicking on an event and going to code it in vb editor, then deleting the
event opening/closing lines and just adding the function. Anyway, it seemed
to work to lock the other controls but not to "unlock" the option button. I
feel sure I was suppose to modify the function in some way that I didn't, or
"call" it or something other than what I did.

I did find what seems like, at first glance, a pretty simple solution of my
own.

I put the "me.allowedits = false" back in the "on_current" event of the form
(I had taken it out to try the function you gave me). Then, I went to the
option button that I needed to be able to "edit", and put a "Me.AllowEdits =
True" on the "on_Mouse Down" event. I had the code I needed to "un"hide the
subform and resize the form already in the "on_click" event. AND, I put
another "Me.AllowEdits = False" in the "on_Lost Focus" event.

It seems to work so far. Maybe there's a reason it's a bad idea to do it
that way....I dunno.

Thanks again for the help. Hopefully, as time goes on, I'll learn more
about functions and where to put them.

CW
 
G

Graham Mandeno

Hi CW

I would put the function in your form module and call it in the Form_Current
event procedure, and also in the AfterUpdate event of the option button:

In Form_Current:
Call LockControls(True)

In YourButton_AfterUpdate:
Call LockControls( YourButton = <value for locked> )

The way you are doing it now should work OK, as the MouseDown event will
still work if AllowEdits is disabled.

You can file my function away for future use where you want to be more
selective about what gets enabled or disabled for editing :)
 
G

Guest

Graham,

Thanks for the reply. I spent some time today messing around with trying to
learn how to use the function, but got called away and didn't get a chance to
do much more. I'll definitely revisit it tomorrow, because I do want to
learn as much as I can.

My way works fine except if a user starts editing the form, and then decides
to show/hide the subform, it will lock the form again when they try to go
back and finish the editing. Certainly something that could be worked
around, but I hate things like that....

I don't expect a reply, but I assume you're saying put the actual function
code in the class module just as a function (not attached to an event), then
add the code you gave to the events you listed.

It's funny, I've got three Access books (one on vba coding) and a ton of web
resources and none of them seem to take into account how elementary someone
like me needs to have the functions explained. In all those resources no one
ever said "To add a function to the class module, you 1., 2., 3.,....

Maybe I'm just dense!

Anyway, thanks again. I think I have enough now to get there with a little
trial and error at worst.

CW

Graham Mandeno said:
Hi CW

I would put the function in your form module and call it in the Form_Current
event procedure, and also in the AfterUpdate event of the option button:

In Form_Current:
Call LockControls(True)

In YourButton_AfterUpdate:
Call LockControls( YourButton = <value for locked> )

The way you are doing it now should work OK, as the MouseDown event will
still work if AllowEdits is disabled.

You can file my function away for future use where you want to be more
selective about what gets enabled or disabled for editing :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Cheese_whiz said:
Graham,

I tried that method and, though I'm sure it works, I had some trouble
getting it to work for me. I wasn't even really sure where exactly I was
suppose to put the function. I ended up selecting the "form" object and
clicking on an event and going to code it in vb editor, then deleting the
event opening/closing lines and just adding the function. Anyway, it
seemed
to work to lock the other controls but not to "unlock" the option button.
I
feel sure I was suppose to modify the function in some way that I didn't,
or
"call" it or something other than what I did.

I did find what seems like, at first glance, a pretty simple solution of
my
own.

I put the "me.allowedits = false" back in the "on_current" event of the
form
(I had taken it out to try the function you gave me). Then, I went to the
option button that I needed to be able to "edit", and put a "Me.AllowEdits
=
True" on the "on_Mouse Down" event. I had the code I needed to "un"hide
the
subform and resize the form already in the "on_click" event. AND, I put
another "Me.AllowEdits = False" in the "on_Lost Focus" event.

It seems to work so far. Maybe there's a reason it's a bad idea to do it
that way....I dunno.

Thanks again for the help. Hopefully, as time goes on, I'll learn more
about functions and where to put them.

CW
 
G

Graham Mandeno

Hi CW

There are many ways to add a function to a module. First, you can just
start typing it in. Typing:
Function x() <enter>
will automatically add the "End Function" line for you, and then you can
just enter the code.

You can also use Insert>Procedure from the menu.

Or, you can simply copy and paste (that would have been the best way to
insert the LockControls function that I wrote for you).

For an event procedure you can click on the ... button on the property sheet
for the linked object (control etc), or you can select the object in the
left-hand combo of the code window, and then select the event from the
right-hand combo.

Also, there are several good add-ins such as MZ-Tools
(http://www.mztools.com) which allow you to set up procedure templates and
add them with very little fuss.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Cheese_whiz said:
Graham,

Thanks for the reply. I spent some time today messing around with trying
to
learn how to use the function, but got called away and didn't get a chance
to
do much more. I'll definitely revisit it tomorrow, because I do want to
learn as much as I can.

My way works fine except if a user starts editing the form, and then
decides
to show/hide the subform, it will lock the form again when they try to go
back and finish the editing. Certainly something that could be worked
around, but I hate things like that....

I don't expect a reply, but I assume you're saying put the actual function
code in the class module just as a function (not attached to an event),
then
add the code you gave to the events you listed.

It's funny, I've got three Access books (one on vba coding) and a ton of
web
resources and none of them seem to take into account how elementary
someone
like me needs to have the functions explained. In all those resources no
one
ever said "To add a function to the class module, you 1., 2., 3.,....

Maybe I'm just dense!

Anyway, thanks again. I think I have enough now to get there with a
little
trial and error at worst.

CW

Graham Mandeno said:
Hi CW

I would put the function in your form module and call it in the
Form_Current
event procedure, and also in the AfterUpdate event of the option button:

In Form_Current:
Call LockControls(True)

In YourButton_AfterUpdate:
Call LockControls( YourButton = <value for locked> )

The way you are doing it now should work OK, as the MouseDown event will
still work if AllowEdits is disabled.

You can file my function away for future use where you want to be more
selective about what gets enabled or disabled for editing :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Cheese_whiz said:
Graham,

I tried that method and, though I'm sure it works, I had some trouble
getting it to work for me. I wasn't even really sure where exactly I
was
suppose to put the function. I ended up selecting the "form" object
and
clicking on an event and going to code it in vb editor, then deleting
the
event opening/closing lines and just adding the function. Anyway, it
seemed
to work to lock the other controls but not to "unlock" the option
button.
I
feel sure I was suppose to modify the function in some way that I
didn't,
or
"call" it or something other than what I did.

I did find what seems like, at first glance, a pretty simple solution
of
my
own.

I put the "me.allowedits = false" back in the "on_current" event of the
form
(I had taken it out to try the function you gave me). Then, I went to
the
option button that I needed to be able to "edit", and put a
"Me.AllowEdits
=
True" on the "on_Mouse Down" event. I had the code I needed to
"un"hide
the
subform and resize the form already in the "on_click" event. AND, I
put
another "Me.AllowEdits = False" in the "on_Lost Focus" event.

It seems to work so far. Maybe there's a reason it's a bad idea to do
it
that way....I dunno.

Thanks again for the help. Hopefully, as time goes on, I'll learn more
about functions and where to put them.

CW

:

Thanks DG. Don't know how I missed that...

CW

:

message

When you say "tag", is that like a smart tag or does it have some
other meaning in your post?

Every Access control has a Tag property, which you can use entirely
for
your own purposes and set to any value you like. You'll find it on
the
Other tab of the control's property sheet in design view.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
G

Guest

Thanks again, Graham! You've been extremely helpful.

I've installed that MZTools and will give it a whirl.

CW

Graham Mandeno said:
Hi CW

There are many ways to add a function to a module. First, you can just
start typing it in. Typing:
Function x() <enter>
will automatically add the "End Function" line for you, and then you can
just enter the code.

You can also use Insert>Procedure from the menu.

Or, you can simply copy and paste (that would have been the best way to
insert the LockControls function that I wrote for you).

For an event procedure you can click on the ... button on the property sheet
for the linked object (control etc), or you can select the object in the
left-hand combo of the code window, and then select the event from the
right-hand combo.

Also, there are several good add-ins such as MZ-Tools
(http://www.mztools.com) which allow you to set up procedure templates and
add them with very little fuss.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Cheese_whiz said:
Graham,

Thanks for the reply. I spent some time today messing around with trying
to
learn how to use the function, but got called away and didn't get a chance
to
do much more. I'll definitely revisit it tomorrow, because I do want to
learn as much as I can.

My way works fine except if a user starts editing the form, and then
decides
to show/hide the subform, it will lock the form again when they try to go
back and finish the editing. Certainly something that could be worked
around, but I hate things like that....

I don't expect a reply, but I assume you're saying put the actual function
code in the class module just as a function (not attached to an event),
then
add the code you gave to the events you listed.

It's funny, I've got three Access books (one on vba coding) and a ton of
web
resources and none of them seem to take into account how elementary
someone
like me needs to have the functions explained. In all those resources no
one
ever said "To add a function to the class module, you 1., 2., 3.,....

Maybe I'm just dense!

Anyway, thanks again. I think I have enough now to get there with a
little
trial and error at worst.

CW

Graham Mandeno said:
Hi CW

I would put the function in your form module and call it in the
Form_Current
event procedure, and also in the AfterUpdate event of the option button:

In Form_Current:
Call LockControls(True)

In YourButton_AfterUpdate:
Call LockControls( YourButton = <value for locked> )

The way you are doing it now should work OK, as the MouseDown event will
still work if AllowEdits is disabled.

You can file my function away for future use where you want to be more
selective about what gets enabled or disabled for editing :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Graham,

I tried that method and, though I'm sure it works, I had some trouble
getting it to work for me. I wasn't even really sure where exactly I
was
suppose to put the function. I ended up selecting the "form" object
and
clicking on an event and going to code it in vb editor, then deleting
the
event opening/closing lines and just adding the function. Anyway, it
seemed
to work to lock the other controls but not to "unlock" the option
button.
I
feel sure I was suppose to modify the function in some way that I
didn't,
or
"call" it or something other than what I did.

I did find what seems like, at first glance, a pretty simple solution
of
my
own.

I put the "me.allowedits = false" back in the "on_current" event of the
form
(I had taken it out to try the function you gave me). Then, I went to
the
option button that I needed to be able to "edit", and put a
"Me.AllowEdits
=
True" on the "on_Mouse Down" event. I had the code I needed to
"un"hide
the
subform and resize the form already in the "on_click" event. AND, I
put
another "Me.AllowEdits = False" in the "on_Lost Focus" event.

It seems to work so far. Maybe there's a reason it's a bad idea to do
it
that way....I dunno.

Thanks again for the help. Hopefully, as time goes on, I'll learn more
about functions and where to put them.

CW

:

Thanks DG. Don't know how I missed that...

CW

:

message

When you say "tag", is that like a smart tag or does it have some
other meaning in your post?

Every Access control has a Tag property, which you can use entirely
for
your own purposes and set to any value you like. You'll find it on
the
Other tab of the control's property sheet in design view.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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