From: Dirk Goldgar on 25 Feb 2010 16:45 "alex" <sql_aid(a)yahoo.com> wrote in message news:846bf56d-2d55-4317-95c5-1c32494b548e(a)d2g2000yqa.googlegroups.com... >I must not understand the Dirty Property... > > I place this code in my form module and it never fires...ever: > > Private Sub Form_Dirty(Cancel As Integer) > > Me.cmdUndo.Enabled = True > Me.cmdSave.Enabled = True > MsgBox "form_dirty fired" > > End Sub > > I'm guessing that if I change the value of my controls the dirty event > should fire. I must have code somewhere that is saving the form > automatically thereby not allowing the form's dirty event to fire... More likely, you have code that is dirtying the form programmatically. The Dirty event only fires when the form is first dirtied by user action (or by assigning to a bound control's Text property). If you have code or a macro that assigns a value to a bound control before the user makes his own changes, then the form is already dirty when the user makes a change, and so the Dirty event doesn't fire. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup)
From: John W. Vinson on 25 Feb 2010 17:32 On Thu, 25 Feb 2010 12:38:05 -0800 (PST), alex <sql_aid(a)yahoo.com> wrote: >What I�m trying to do is enable a Save and Undo button when the record >becomes dirty. I know the record is automatically saved when the next >record is displayed, but I�d like to give the user an option to hit >the Save button or highlight the Undo button when it can actually undo >something! PMFJI, but I don't think the Dirty event is appropriate for this purpose. The Form's BeforeUpdate event fires right before the record is written to disk, and is cancellable. You could use code like Private Sub Form_BeforeUpdate(Cancel as Integer) Dim iAns As Integer iAns = MsgBox("Click OK to save, Cancel to cancel", vbOKCancel) If iAns = vbCancel Then Cancel = True Me.Undo End If End Sub However, in my experience, users will ABSOLUTELY HATE this: "yes, dammit, I did want to save the record, that's why I entered it!!!!" and will just automatically click OK. Training users that "when you enter data, it enters the data into the table" is easier all around. -- John W. Vinson [MVP]
From: Dirk Goldgar on 25 Feb 2010 18:07 "John W. Vinson" <jvinson(a)STOP_SPAM.WysardOfInfo.com> wrote in message news:kbudo55n9f8u2saej7antm1m9k4bu9oo7d(a)4ax.com... > On Thu, 25 Feb 2010 12:38:05 -0800 (PST), alex <sql_aid(a)yahoo.com> wrote: > >>What I'm trying to do is enable a Save and Undo button when the record >>becomes dirty. I know the record is automatically saved when the next >>record is displayed, but I'd like to give the user an option to hit >>the Save button or highlight the Undo button when it can actually undo >>something! > > PMFJI, but I don't think the Dirty event is appropriate for this purpose. > The > Form's BeforeUpdate event fires right before the record is written to > disk, > and is cancellable. You could use code like I don't think I agree with you, John, about what Alex is trying to do. As I understand it, he's not putting up a confirmation dialog, but just having Save/Undo buttons be enabled only when the form is dirty. In other words, the buttons should be disabled until a record has been modified, at which point they should be enabled. For that purpose, I think the Dirty event is the event to use. To my mind, this is good UI design, making it clear to the user when a particular button is operable. Of course, there is no need for a Save button, and I wouldn't have one on my own forms. But an Undo button? Sure, why not? -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup)
From: alex on 25 Feb 2010 19:04 On Feb 25, 6:07 pm, "Dirk Goldgar" <d...(a)NOdataSPAMgnostics.com.invalid> wrote: > "John W. Vinson" <jvinson(a)STOP_SPAM.WysardOfInfo.com> wrote in messagenews:kbudo55n9f8u2saej7antm1m9k4bu9oo7d(a)4ax.com... > > > On Thu, 25 Feb 2010 12:38:05 -0800 (PST), alex <sql_...(a)yahoo.com> wrote: > > >>What I'm trying to do is enable a Save and Undo button when the record > >>becomes dirty. I know the record is automatically saved when the next > >>record is displayed, but I'd like to give the user an option to hit > >>the Save button or highlight the Undo button when it can actually undo > >>something! > > > PMFJI, but I don't think the Dirty event is appropriate for this purpose. > > The > > Form's BeforeUpdate event fires right before the record is written to > > disk, > > and is cancellable. You could use code like > > I don't think I agree with you, John, about what Alex is trying to do. As I > understand it, he's not putting up a confirmation dialog, but just having > Save/Undo buttons be enabled only when the form is dirty. In other words, > the buttons should be disabled until a record has been modified, at which > point they should be enabled. For that purpose, I think the Dirty event is > the event to use. > > To my mind, this is good UI design, making it clear to the user when a > particular button is operable. Of course, there is no need for a Save > button, and I wouldn't have one on my own forms. But an Undo button? Sure, > why not? > > -- > Dirk Goldgar, MS Access MVP > Access tips:www.datagnostics.com/tips.html > > (please reply to the newsgroup) Dirk, I'm sure you're right...I'm going to do some testing and post back. Thanks for the advice about the save button (your advice too John). I loop through the controls on this form to advise the user when he/ she can leave the record (if certain textboxes are null you can't create a record). That's where the cmdSave.Enabled comes in handy...so they know they've got a "complete" record. alex
From: John W. Vinson on 25 Feb 2010 19:22
On Thu, 25 Feb 2010 18:07:21 -0500, "Dirk Goldgar" <dg(a)NOdataSPAMgnostics.com.invalid> wrote: > As I >understand it, he's not putting up a confirmation dialog, but just having >Save/Undo buttons be enabled only when the form is dirty. ah... sorry! Quite right. -- John W. Vinson [MVP] |