Edit - Save Buttons on Form - OnClick "not working"?

G

Guest

I put 2 Labels at the bottom of my form, the first named "EditButton" with
text "EDIT" and the second named "SaveButton" with text "SAVE". The form's
Data Entry property is set to "No". I put these procedures in the On_Click
Event for these buttons:

Private Sub EditButton_Click()

Me.AllowEdits = True

End Sub


Private Sub SaveButton_Click()

Me.AllowEdits = False

End Sub

(I've got other actions occuring, but they aren't where my problem is.)

When the form opens, it can't be edited. When the "Edit" button is clicked,
the form then can be edited. But when the "Save" button is clicked, the form
can still be edited - the "Me.AllowEdits = False" statement appears to "not
work".

Anyone see what's wrong? Thanks - John D
 
J

jeff

John

Firstly I assume you mean you placed 2 BUTTONS on the form and NOT Labels.
Labels do not have EVENTS. If you placed LABELS on the form then.....

DATAENTRY property when set to NO means that the form is not in DATAENTRY
(ie Adding a new record mode) but existig records can be edited.
If you set it to YES then the form will always be the Add records mode.

I suspect you still have the default for the FORM proeprty AllowEdits set to
YES. This would produce the behaviour you are talking about. Clicking on
either LABEL would not cause any action and hence it appears that the form
is placed in EDIT mode which it was in by default. CLinking on the SAVE
label actually does nothing so the form remains in its default mode....

Am I on the right track? Hope this helps...

cheers
Jeff
 
J

jeff

John

OOOPS

missed the last statement where you said in operation the foirm cant be
edited and after clicking the edit button it can!! there fore I assume you
are using buttons and the problems is diferent to what I
assumed....apologies...

It would appear that you need to save the changes made before setting the
form to not allow edits. If you test this by running your form but not
making any edits you will find the Save button does turn off editing. But if
you made changes to the data and then click the save button it does not turn
off editing. You need to do something like:-

Private Sub SaveButton_Click()

If Me.Dirty Then
Me.Refresh
End If
Me.AllowEdits = False

End Sub

or you can get more elaborate with the saving....

Cheers
Jeff
 
G

Guest

Tah Dah - yep, I needed to save changes before AllowEdits could be set to
False. Thanks.

In the past few months I've crammed several hundred pages from 5 books about
VBA for Access and Access in general into my aging skull, and it's taking a
while for all the distinctions between things like the difference between
DataEntry and AllowEdits to settle in (although usually it's a slap my head
sort of "Geez - that's obvious" moment).

HOWEVER - well, yes, they ARE LABELS. One of the things I wanted to do was
change the Visible property of these "buttons" so that EDIT was visible from
the beginning, but when clicked, it disappears and SAVE and another "button"
CANCEL become visible. I don't think Command Buttons can do that (right?).
(Another post by an MVP says Command Buttons are "pretty stupid" - not very
flexible.) I see 5 Events for these Labels in their Property Sheets:

On Click
On Dbl Click
On Mouse Down
On Mouse Move
On Mouse Up

So - I do have access to the On Click Event for these Labels.

Thanks Jeff - I continue to be amazed at how many of you folks are willing
to spend time helping us bumbling newbies figure things out!

John D
 
J

jeff

kewl...im glad it helped you out.

yes of course the events on labels do work. But you can achieve the
disabling of the edit button after it has been pressed etc...its just a
matter of moving the focus and then disabling/enabling things. I do this all
the time...example below...

'===============================================================================
Private Sub btnEdit_Click()
'-------------------------------------------------------------------------------
' Comments :
' Author : Jeff Date : 10/10/2006
' Parameters :
' Returns :
' Usuage :
'

On Error GoTo PROC_Error

Me.SchedCourseID.SetFocus
Me.AllowEdits = True
Me.btnSave.Enabled = True
Me.btnAdd.Enabled = False
Me.btnEdit.Enabled = False

'subform
Me.frmMaintain_CourseBookings_Company_Attendees.Form.AllowAdditions =
True
Me.frmMaintain_CourseBookings_Company_Attendees.Form.AllowDeletions =
True
Me.frmMaintain_CourseBookings_Company_Attendees.Form.AllowEdits = True

PROC_Exit:
Exit Sub

PROC_Error:
MsgBox Error$
Resume PROC_Exit

End Sub


BTW...I am an aging skull as well..(53yo to be exact!) but I understand what
youre saying...it doesnt get easier as you get older...just slower and more
wiser...hehe

cheers
jeff
 

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