My Assistant
|
|
Jan 18 2005, 05:32 AM
Post
#1
|
|
|
UtterAccess Addict Posts: 251 From: Ireland |
I have a very large form where I have added three command buttons:
Undo - Save - Close I want the Undo & Save Button to be disabled until the form becomes dirty when a record has been changed. Then the Undo & Save buttons become enabled and the Close button becomes disables until one of the Undo & Save buttons is selected. At the moment I am using the following code in the "On Timer" event of the form which seems to be working sometimes but not all the time and I have read that using the "On Timer" is not the best solution for alot of code. Here's my code: Private Sub Form_Timer() On Error Resume Next Static bFlag As Boolean If Me.Dirty Then If Not bFlag Then Me!btnUndo.Enabled = True Me!butSave.Enabled = True Me!ExitPropertiesForm.Enabled = False bFlag = True End If Else If bFlag Then 'Me.ViewReports.SetFocus Me!btnUndo.Enabled = False Me!butsave.Enabled = False Me!ExitPropertiesForm.Enabled = True bFlag = False End If End If End Sub ------------------------------------------------------------------------------------------------------------ should I be using something similar to this in a different event (e.g After Update event) |
|
|
|
![]() |
Jan 18 2005, 06:11 AM
Post
#2
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
You could use the "On Dirty" event of the form to tigger your code. Here is an example from the help file from the "On Dirty" property. Dirty Event — Event Procedures Example The following example enables the btnUndo button when data is changed. The UndoEdits( ) subroutine is called from the Dirty event of text box controls. Clicking the enabled btnUndo button restores the original value of the control by using the OldValue property. Private Sub Form_Dirty() If Me.Dirty Then Me!btnUndo.Enabled = True ' Enable button. Else Me!btnUndo.Enabled = False ' Disable button. End If End Sub Sub btnUndo_Click() Dim ctlC As Control ' For each control. For Each ctlC in Me.Controls If ctlC.ControlType = acTextBox Then ' Restore Old Value. ctlC.Value = ctlC.OldValue End If Next ctlC End Sub HTH's (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Jan 18 2005, 06:50 AM
Post
#3
|
|
|
UtterAccess Addict Posts: 251 From: Ireland |
Hi Larry
Tried the above but the problem im having is when I edit a record the Undo button becomes enabled, After i select the undo button to undo the changes this button remains enabled. Where can I get this to become disabled until the "On Dirty" event is reached again |
|
|
|
Jan 18 2005, 07:24 AM
Post
#4
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
I seem to be having a day where nothings working, I tried to emulate the code example on a simple form/table and can't seem to trigger the dirty event to "True" when I edit a simple control/field on the form. You may (not tested) be able to call the forms dirty event after you have clicked the undo button..? eg: Call Form_Dirty() HTH's (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Jan 18 2005, 07:40 AM
Post
#5
|
|
|
UtterAccess VIP Posts: 2,579 From: Abu Dhabi, U.A.E |
Try this
Private Sub Form_Dirty(Cancel As Integer) Sub btnUndo_Click() You can also add some code for the save button to disable it and the undo button. HTH |
|
|
|
Jan 18 2005, 08:38 AM
Post
#6
|
|
|
UtterAccess Addict Posts: 251 From: Ireland |
Hi All
I have being playing around with this for a while and this is what ive come up with. Ive added to the following code: ---------------------------------------------------- Public Sub Form_Dirty(Cancel As Integer) Me!btnUndo.Enabled = True ' Disable button. Me!btnSave.Enabled = True Me!ExitPropertiesForm.Enabled = False End Sub -------------------------------------------------------- Private Sub btnUndo_Click() DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70 Me.ExitPropertiesForm.Enabled = True Me.ExitPropertiesForm.SetFocus End Sub ------------------------------------------------------------ Private Sub btnSave_Click() DoCmd.SetWarnings False DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 DoCmd.SetWarnings True Me.ExitPropertiesForm.Enabled = True Me.ExitPropertiesForm.SetFocus End Sub ----------------------------------------------------------------------- Private Sub ExitPropertiesForm_GotFocus() Me.btnUndo.Enabled = False Me.btnSave.Enabled = False End Sub --------------------------------------------------------------------- This seems to be working pritty good except when I open the form acFirst Record is selected. When this record is edited it does not trigger the (On Dirty) event alot of the time. If i select another record on the form, the code works perfectly. STRANGE?? Any suggestions |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 22nd May 2013 - 07:28 PM |