AllowEdits Toggle button not working


U

Unbridled

I have used Ken Sheridan's code below (Thanks Ken!) to toggle a
subform to keep the information from being edited inadvertantly. The
button is not working on click() and the AllowEdits is not changing
from false to true.

The button, named cmdlock is located on the footer section of a
subform (named Subform1) set up as continuous forms simulated to look
like a datasheet view. The main form is named SPACES. I set up a tab
control on SPACES then placed Subform1 within that.

I appear to be stuck in the current() procedure since the button
caption will not toggle. Any help appreciated.

THIS FUNCTION SETS THE ALLOWEDITS to FALSE AS THE DEFAULT. Placed on
Subform1.

Private Sub Form_Current()
Dim ctrl As Control
Set ctrl = Me.cmdlock
Me.AllowEdits = False
ctrl.Caption = "Click to Edit"
ctrl.Enabled = Not Me.NewRecord
End Sub

THIS WAS ALSO PLACED ON SUBFORM1
Private Sub Form_AfterInsert()
Dim ctrl As Control
Set ctrl = Me.cmdlock
Me.AllowEdits = False
ctrl.Enabled = True
ctrl.Caption = "Click to Edit"

End Sub


HERE IS THE CLICK FUNCTION (placed on the button)
Private Sub cmdlock_Click()
Dim ctrl As Control
Set ctrl = Me.ActiveControl
Me.AllowEdits = True
ctrl.Caption = IIf(Me.AllowEdits, "Click to Lock", "Click to
Edit")
End Sub
 
Ad

Advertisements

B

bcap

In the properties sheet for the button, on the Event tab, make sure "On
Click" is not empty, it should be set to [Event Procedure].
 
Ad

Advertisements

D

Dirk Goldgar

Unbridled said:
I have used Ken Sheridan's code below (Thanks Ken!) to toggle a
subform to keep the information from being edited inadvertantly. The
button is not working on click() and the AllowEdits is not changing
from false to true.

The button, named cmdlock is located on the footer section of a
subform (named Subform1) set up as continuous forms simulated to look
like a datasheet view. The main form is named SPACES. I set up a tab
control on SPACES then placed Subform1 within that.

I appear to be stuck in the current() procedure since the button
caption will not toggle. Any help appreciated.

THIS FUNCTION SETS THE ALLOWEDITS to FALSE AS THE DEFAULT. Placed on
Subform1.

Private Sub Form_Current()
Dim ctrl As Control
Set ctrl = Me.cmdlock
Me.AllowEdits = False
ctrl.Caption = "Click to Edit"
ctrl.Enabled = Not Me.NewRecord
End Sub

THIS WAS ALSO PLACED ON SUBFORM1
Private Sub Form_AfterInsert()
Dim ctrl As Control
Set ctrl = Me.cmdlock
Me.AllowEdits = False
ctrl.Enabled = True
ctrl.Caption = "Click to Edit"

End Sub


HERE IS THE CLICK FUNCTION (placed on the button)
Private Sub cmdlock_Click()
Dim ctrl As Control
Set ctrl = Me.ActiveControl
Me.AllowEdits = True
ctrl.Caption = IIf(Me.AllowEdits, "Click to Lock", "Click to
Edit")
End Sub


This is a command button, not a toggle button, yes? If the form's
AllowEdits property is set to No/False, a toggle button can't even be
updated.

Assuming that it is a command button, can you verify that other VBA code in
your database runs? What version of Access are you using? If it's Access
2007, is the database in a trusted location? If you set a breakpoint in the
button's Click event procedure, does the code halt at the breakpoint when
you click the button?
 

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