allowEdits

  • Thread starter injanib via AccessMonster.com
  • Start date
I

injanib via AccessMonster.com

I have my form property setup to AllowEdits=false.
When the form is opended in edits mode all fields are locked, which is what I
want so that records are not accidentaly edited. I have created a button that
runs the line, Me.AllowEdits=True, to unlock the fields so that a record can
be changed if need be. Once the changes are made I have another button the
should lock the fields again by running the line, Me.AllowEdits=false. But
the second button does not work. It does not lock the fields.
Here is the codes.

Private Sub Save_Click()
On Error GoTo Err_Save_Click

Me.AllowEdits = False

Exit_Save_Click:
Exit Sub

Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click

End Sub
 
A

Allen Browne

If the form is dirty (has unsaved edits in progress) at the time you set
AllowEdits to False, Microsoft allows you to continue editing until that
record is saved. Otherwise you would have painted yourself into a corner.

Therefore you need to force the save before you turn AllowEdits off. Add the
line:
RunCommand acCmdSaveRecord
above your Me.AllowEdits = False.

Occassionally we see people doing very silly things such as dirtying the
form in its Current event, or the form's AfterUpdate event. In this case the
form is *always* dirty, so your attempt to set AllowEdits to False won't
work at all.

One of the problems with setting AllowEdits is that even unbound controls
become locked - not useful if use an unbound combo for navigation or
filtering. If you strike this problem, you can use the code in this link to
set the Locked property of the bound controls instead:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html
 
I

injanib via AccessMonster.com

Thanks,
Why do I get a Compile error when I enter the line
=LockBoundControls([Form],True)
in te onload event property of the file?

Allen said:
If the form is dirty (has unsaved edits in progress) at the time you set
AllowEdits to False, Microsoft allows you to continue editing until that
record is saved. Otherwise you would have painted yourself into a corner.

Therefore you need to force the save before you turn AllowEdits off. Add the
line:
RunCommand acCmdSaveRecord
above your Me.AllowEdits = False.

Occassionally we see people doing very silly things such as dirtying the
form in its Current event, or the form's AfterUpdate event. In this case the
form is *always* dirty, so your attempt to set AllowEdits to False won't
work at all.

One of the problems with setting AllowEdits is that even unbound controls
become locked - not useful if use an unbound combo for navigation or
filtering. If you strike this problem, you can use the code in this link to
set the Locked property of the bound controls instead:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html
I have my form property setup to AllowEdits=false.
When the form is opended in edits mode all fields are locked, which is
[quoted text clipped - 20 lines]
Resume Exit_Save_Click
End Sub
 
A

Allen Browne

Did you place the expression into the OnLoad *property* (i.e. in the
Properties box)?

Or did you place it in the code window (where it won't compile)?
If you want to use an event procedure instead of setting the property, try:
Call LockBoundControls(Me, True)

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

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

injanib via AccessMonster.com said:
Thanks,
Why do I get a Compile error when I enter the line
=LockBoundControls([Form],True)
in te onload event property of the file?

Allen said:
If the form is dirty (has unsaved edits in progress) at the time you set
AllowEdits to False, Microsoft allows you to continue editing until that
record is saved. Otherwise you would have painted yourself into a corner.

Therefore you need to force the save before you turn AllowEdits off. Add
the
line:
RunCommand acCmdSaveRecord
above your Me.AllowEdits = False.

Occassionally we see people doing very silly things such as dirtying the
form in its Current event, or the form's AfterUpdate event. In this case
the
form is *always* dirty, so your attempt to set AllowEdits to False won't
work at all.

One of the problems with setting AllowEdits is that even unbound controls
become locked - not useful if use an unbound combo for navigation or
filtering. If you strike this problem, you can use the code in this link
to
set the Locked property of the bound controls instead:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html
I have my form property setup to AllowEdits=false.
When the form is opended in edits mode all fields are locked, which is
[quoted text clipped - 20 lines]
Resume Exit_Save_Click
End Sub
 
I

injanib via AccessMonster.com

Allen,

I love how this method works. its great! Is it possible to have it so that
the form is not loaded locked when opened in add mode? I just wish I didn't
have to click the unlock button before I start entering new record.

Allen said:
Did you place the expression into the OnLoad *property* (i.e. in the
Properties box)?

Or did you place it in the code window (where it won't compile)?
If you want to use an event procedure instead of setting the property, try:
Call LockBoundControls(Me, True)
Thanks,
Why do I get a Compile error when I enter the line
[quoted text clipped - 31 lines]
 
A

Allen Browne

Sure. Just test to see if you are at a new record when the form loads.

Use this line of code in the event pocedure for the form's Load event:

Call LockBoundControls(Me, Not Me.NewRecord)

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

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

injanib via AccessMonster.com said:
I love how this method works. its great! Is it possible to have it so that
the form is not loaded locked when opened in add mode? I just wish I
didn't
have to click the unlock button before I start entering new record.

Allen said:
Did you place the expression into the OnLoad *property* (i.e. in the
Properties box)?

Or did you place it in the code window (where it won't compile)?
If you want to use an event procedure instead of setting the property,
try:
Call LockBoundControls(Me, True)
Thanks,
Why do I get a Compile error when I enter the line
[quoted text clipped - 31 lines]
Resume Exit_Save_Click
End Sub
 
I

injanib via AccessMonster.com

Awesome,
One more thing. Can I make the button toggle between "Change" and "Save"?

Allen said:
Sure. Just test to see if you are at a new record when the form loads.

Use this line of code in the event pocedure for the form's Load event:

Call LockBoundControls(Me, Not Me.NewRecord)
I love how this method works. its great! Is it possible to have it so that
the form is not loaded locked when opened in add mode? I just wish I
[quoted text clipped - 14 lines]
 
A

Allen Browne

You can, but you will need to modify the code so that it tests for these
words in cmdLock_Click(), and assigns the desired words at the end of the
LockBoundControls() function instead of "Un&lock" and "&Lock".

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

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

injanib via AccessMonster.com said:
Awesome,
One more thing. Can I make the button toggle between "Change" and "Save"?

Allen said:
Sure. Just test to see if you are at a new record when the form loads.

Use this line of code in the event pocedure for the form's Load event:

Call LockBoundControls(Me, Not Me.NewRecord)
I love how this method works. its great! Is it possible to have it so
that
the form is not loaded locked when opened in add mode? I just wish I
[quoted text clipped - 14 lines]
Resume Exit_Save_Click
End Sub
 
C

clh333

You can, but you will need to modify the code so that it tests for these
words in cmdLock_Click(), and assigns the desired words at the end of the
LockBoundControls() function instead of "Un&lock" and "&Lock".

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.



Awesome,
One more thing. Can I make the button toggle between "Change" and "Save"?
Allen said:
Sure. Just test to see if you are at a new record when the form loads.
Use this line of code in the event pocedure for the form's Load event:
Call LockBoundControls(Me, Not Me.NewRecord)
I love how this method works. its great! Is it possible to have it so
that
the form is not loaded locked when opened in add mode? I just wish I
[quoted text clipped - 14 lines]
Resume Exit_Save_Click
End Sub- Hide quoted text -

- Show quoted text -

Thanks for your tip about forcing the save before changing the
AllowEdits property. It may be of interest to others to know that,
although the parent form sets the properties for subforms upon
startup, it does not do so when changing them from code. I found that
a fully-qualified reference to the subform was required to synchronize
their behavior.

-CLH333-
 
I

injanib via AccessMonster.com

Allen,
I use your codes on two forms. It works perfect on one of them that is loaded
in add mode from the switchboard. The other one opens in add mode by running
the line

DoCmd.OpenForm "FormName", , , acAdd

from a command button. Even though I have

Call LockBoundControls(Me, Not Me.NewRecord)

in the afterload property event of the form, it still opens the form in add
mode with all the controls locked.

Allen said:
You can, but you will need to modify the code so that it tests for these
words in cmdLock_Click(), and assigns the desired words at the end of the
LockBoundControls() function instead of "Un&lock" and "&Lock".
Awesome,
One more thing. Can I make the button toggle between "Change" and "Save"?
[quoted text clipped - 11 lines]
 
A

Allen Browne

What event procedure did you put this code in?

I'm not familiar with the AfterLoad event.

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

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

injanib via AccessMonster.com said:
Allen,
I use your codes on two forms. It works perfect on one of them that is
loaded
in add mode from the switchboard. The other one opens in add mode by
running
the line

DoCmd.OpenForm "FormName", , , acAdd

from a command button. Even though I have

Call LockBoundControls(Me, Not Me.NewRecord)

in the afterload property event of the form, it still opens the form in
add
mode with all the controls locked.

Allen said:
You can, but you will need to modify the code so that it tests for these
words in cmdLock_Click(), and assigns the desired words at the end of the
LockBoundControls() function instead of "Un&lock" and "&Lock".
Awesome,
One more thing. Can I make the button toggle between "Change" and
"Save"?
[quoted text clipped - 11 lines]
Resume Exit_Save_Click
End Sub
 
I

injanib via AccessMonster.com

Sorry, I meant the load event procedure of the form that is opened via On
click event procedure of a button with code (DoCmd. OpenForm "FormName", , ,
acAdd)

Allen said:
What event procedure did you put this code in?

I'm not familiar with the AfterLoad event.
Allen,
I use your codes on two forms. It works perfect on one of them that is
[quoted text clipped - 23 lines]
 
A

Allen Browne

I just tested it, and:
DoCmd.OpenForm "Form1",,,,acFormAdd
opens the form *unlocked* when you have this line in the form's Load event:
Call LockBoundControls(Me, Not Me.NewRecord)

This is assuming that the form is not is not already open (not even in
design view.)

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

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

injanib via AccessMonster.com said:
Sorry, I meant the load event procedure of the form that is opened via On
click event procedure of a button with code (DoCmd. OpenForm "FormName", ,
,
acAdd)

Allen said:
What event procedure did you put this code in?

I'm not familiar with the AfterLoad event.
Allen,
I use your codes on two forms. It works perfect on one of them that is
[quoted text clipped - 23 lines]
Resume Exit_Save_Click
End Sub
 
I

injanib via AccessMonster.com

I realized that I was missing one extra comma in the command line of opening
form in add mode. It is working perfect now, however, I would love to be able
to set the enabled property of the Lock/Unlock button to false in add mode
for the sake of avoiding user confusion.

Allen said:
I just tested it, and:
DoCmd.OpenForm "Form1",,,,acFormAdd
opens the form *unlocked* when you have this line in the form's Load event:
Call LockBoundControls(Me, Not Me.NewRecord)

This is assuming that the form is not is not already open (not even in
design view.)
Sorry, I meant the load event procedure of the form that is opened via On
click event procedure of a button with code (DoCmd. OpenForm "FormName", ,
[quoted text clipped - 10 lines]
 

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