Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: AllowEdits

Geek News

AllowEdits
lhtan123 11/17/2008 9:30:00 AM
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

Re: AllowEdits
Stefan Hoffmann <ste5an[ at ]ste5an.de> 11/17/2008 9:43:37 AM
hi,

lhtan123 wrote:
[Quoted Text]
> 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 <--
Re: AllowEdits
"Keith Wilby" <here[ at ]there.com> 11/17/2008 10:25:50 AM
"lhtan123" <lhtan123[ at ]discussions.microsoft.com> wrote in message
news:BCE7744F-E5A4-4C80-A5D0-4C97EF43A38B[ at ]microsoft.com...

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

Re: AllowEdits
"Linq Adams via AccessMonster.com" <u28780[ at ]uwe> 11/17/2008 5:47:12 PM
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

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1

Re: AllowEdits
lhtan123 11/19/2008 2:14:02 AM
Thanks. It works.

But I just wonder why "AllowEdits" alone can't do the job.

"Linq Adams via AccessMonster.com" wrote:

[Quoted Text]
> 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
>
> --
> There's ALWAYS more than one way to skin a cat!
>
> Answers/posts based on Access 2000/2003
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1
>
>
Re: AllowEdits
"Linq Adams via AccessMonster.com" <u28780[ at ]uwe> 11/19/2008 4:53:52 AM
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.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net