AcFormEdit

P

Pigeon70

Hi there!

I want to have my form "School/Teacher Details" open with edits, adding and
deleting not possible. I also want to create a button that when pressed will
allow edits, adding and deleting.

So far I have selected 'no' for allow edit, and add in the form properties.
I am attempting to write event procedure code for a button control that will
override these properties. Using the code below I have only managed to open
the form in design mode. Any clues to get it to do what I want would be much
appreciated.

Private Sub Edit_Form_Click()
On Error GoTo Err_Edit_Form_Click

DoCmd.OpenForm "School/Teacher Details", View:=acFormEdit

Exit_Edit_Form_Click:
Exit Sub

Err_Edit_Form_Click:
MsgBox Err.Description
Resume Exit_Edit_Form_Click

End Sub

Pam
 
D

Dirk Goldgar

Pigeon70 said:
Hi there!

I want to have my form "School/Teacher Details" open with edits, adding
and
deleting not possible. I also want to create a button that when pressed
will
allow edits, adding and deleting.

So far I have selected 'no' for allow edit, and add in the form
properties.
I am attempting to write event procedure code for a button control that
will
override these properties. Using the code below I have only managed to
open
the form in design mode. Any clues to get it to do what I want would be
much
appreciated.

Private Sub Edit_Form_Click()
On Error GoTo Err_Edit_Form_Click

DoCmd.OpenForm "School/Teacher Details", View:=acFormEdit

Exit_Edit_Form_Click:
Exit Sub

Err_Edit_Form_Click:
MsgBox Err.Description
Resume Exit_Edit_Form_Click

End Sub

Pam


Pam, is this button on the form itself? If so, then all you need to do is
this:

Private Sub Edit_Form_Click()

Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True

End Sub
 
P

Pigeon70

Hi Dirk,

That was fantastic - it works beautifully! Thanks for getting back to me so
quick.
Thanks heaps
Pam
 
P

Pigeon70

Hi again,

The code below worked beautifully for my form allowing edits, however, it
did not allow the subform to accept edits even though the allow edits,
deletions and additions properties were set to yes.

Have you got any suggestions?

Pam
 
D

Dirk Goldgar

Pigeon70 said:
Hi again,

The code below worked beautifully for my form allowing edits, however, it
did not allow the subform to accept edits even though the allow edits,
deletions and additions properties were set to yes.

Have you got any suggestions?


You're right; if you don't allow edits for the form, the subform won't be
editable either. If you think about it, that makes sense -- in principle --
because the subform is just another control on the form. Did you mention
this subform before? If so, I didn't notice it.

There are a couple of ways to address this problem. One is to leave the
main form's AllowEdits property set to True, but set the Locked property of
all the bound controls on that form to True when you want to make that form
uneditable, and False when you want to make the form editable. In other
words, where before you had:

Me.AllowEdits = False

.... now you'd have:

Me.SomeField.Locked = True
Me.SomeOtherField.Locked = True
' ... etc. for all bound controls

Conversely, where before you had:

Me.AllowEdits = True

.... now you'd have:

Me.SomeField.Locked = False
Me.SomeOtherField.Locked = False
' ... etc. for all bound controls

Get the picture?

The other way to do this, that I can think of offhand, is to set the main
form's AllowEdits property to True in the subform control's Enter event, and
then set it back to False in the subform control's Exit event. Actually,
you can't just set it to False when you exit the subform -- you need to set
it back to whatever it was when you entered. So you need to use a
module-level variable to save the value of that property before you change
it. Something like this:

'----- start of code -----
Dim mblnAllowEdits As Boolean ' declared at module level

Private Sub YourSubform_Enter()

mblnAllowEdits = Me.AllowEdits

End Sub

Private Sub YourSubform_Exit(Cancel As Integer)

Me.AllowEdits = mblnAllowEdits

End Sub
'----- end of code -----

This would be in addition to the code that I gave you in my previous
message, that sets the various Allow... properties.
 
Top