AllowEdits

L

lhtan123

A form is disabled for editing on load by using "Me.AllowEdits = false".

Editing is enabled when a user clicks on a label called "Edit". Below is
what I intend to do:

Private Sub lblEdit_Click()

If Me.lblEdit.Caption = "Edit" Then
Me.AllowEdits = True
Me.lblEdit.Caption = "Disable Edit"
Else
If Me.lblEdit.Caption = "Disable Edit" Then
Me.AllowEdits = False
Me.lblEdit.Caption = "Edit"
End If
End If
End Sub

*************
The first block of "IF" statement works but not the second one.

When I clicked on the label with "Disable Edit", the form is still editable.
How could I disable it ?

Regards
LH
 
S

Stefan Hoffmann

hi,
The first block of "IF" statement works but not the second one.
When I clicked on the label with "Disable Edit", the form is still editable.
How could I disable it ?
It works, basically, but I think your label text is irritating.

Change your code:

If Not Me.Dirty Then
Me.AllowEdits = Not Me.AllowEdits
If Me.AllowEdits Then
lblEdit.Caption = "Edit Enabled"
Else
lblEdit.Caption = "Edit Disabled"
End If
End if

The first condition ensures that you don't switch the mode while you are
editing something. If you want to save data from an ongoing editing
process use this:

On Local Error GoTo LocalError

If Not Me.Dirty Then
Me.Dirty = False
End If

Me.AllowEdits = Not Me.AllowEdits
If Me.AllowEdits Then
lblEdit.Caption = "Edit Enabled"
Else
lblEdit.Caption = "Edit Disabled"
End If

Exit Sub

LocalError:
MsgBox "Cannot save data." & vbCrLf & Err.Description


mfG
--> stefan <--
 
K

Keith Wilby

Try

Private Sub lblEdit_Click()

If Me.lblEdit.Caption = "Edit" Then
Me.AllowEdits = True
Me.lblEdit.Caption = "Disable Edit"
Else
Me.AllowEdits = False
Me.lblEdit.Caption = "Edit"
End If

End Sub
 
L

Linq Adams via AccessMonster.com

Actually, adding a single line

If Me.Dirty Then Me.Dirty = False


to your current code should do it:

Private Sub lblEdit_Click()

If Me.lblEdit.Caption = "Edit" Then
Me.AllowEdits = True
Me.lblEdit.Caption = "Disable Edit"
Else
If Me.lblEdit.Caption = "Disable Edit" Then
If Me.Dirty Then Me.Dirty = False
Me.AllowEdits = False
Me.lblEdit.Caption = "Edit"
End If
End If
End Sub
 
L

Linq Adams via AccessMonster.com

It's simple, really, you cannot change AllowEdits from Yes to No ***while you
are still editing*** a record! Once in Edit Mode, you remain in Edit Mode
until the edited data is either saved or dumped.

If Me.Dirty Then Me.Dirty = False

forces Access to save the data.
 

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