If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Dirty Expression
Throughout a database, I have used a command button in forms to close the
form when clicked. While it has worked for a long time, recently when I add a new Command button to do the same thing in a new form, I get the message “You entered an expression that has an invalid reference to property Dirty” How do I figure out the code that is causing the problem? The old ones are still working I am just not able to add new ones that close a form. However, I can add new command buttons that open forms, print, etc, so I am not sure where I went wrong. Thanks for your help. -- Rose |
#2
|
|||
|
|||
Dirty Expression
You don't give your code for closing the form, but I assume it involves
checking to see if the current record is, in fact, dirty and forcing the saving of the record before closing the form. This is done to ensure that any validation code be run. This code usually follows the syntax If Me.Dirty Then Me.Dirty = False End If DoCmd.Close I suspect that your form is unbound, and unbound forms don't have a Dirty Property, and thus will pop an error with this code. I understand that this code is used by the command button wizard in ACC2007 when generating a "CLOSE" button. Go into the code window to the OnClick sub for your button and remove the If Me.Dirty Then Me.Dirty = False End If part of the code. -- 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/For...forms/200802/1 |
#3
|
|||
|
|||
Dirty Expression
Unbound forms don't have a Dirty property.
Presumably you have some code that you call from command buttons on several forms throughout the database. So you have a function like the one below in a standard module, and you call it either by setting the close button's On Click property to exactly this (don't replace the "Form" part): =CloseForm([Form]) or by setting the property to: [Event Procedure] and then adding this line to the code: Call CloseForm(Me) Public Function CloseForm(frm As Form) As Boolean On Error Goto Err_Handler 'Purpose: Close a form, saving a record if necessary 'Return: True if the form closed. 'Note: Avoids this bug: http://allenbrowne.com/bug-01.html 'If it's a bound form, save if necessary. If frm.RecordSource vbNullString Then If frm.Dirty Then frm.Dirty = False End If 'Close the form. DoCmd.Close acForm, frm.Name 'If we got here without error, the form closed successfully. CloseForm = True Exit_Hander: Exit Function Err_Handler: MsgBox "Error " & Err.Number & ": " & Err.Description Resume Exit_Handler End Function -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Rose" wrote in message ... Throughout a database, I have used a command button in forms to close the form when clicked. While it has worked for a long time, recently when I add a new Command button to do the same thing in a new form, I get the message “You entered an expression that has an invalid reference to property Dirty” How do I figure out the code that is causing the problem? The old ones are still working I am just not able to add new ones that close a form. However, I can add new command buttons that open forms, print, etc, so I am not sure where I went wrong. Thanks for your help. -- Rose |
#4
|
|||
|
|||
Dirty Expression
Your information was very helpful. Has this problem been fixed yet. I have
many users that rely on the Command Button Wizard to work correctly. They are NOT programmers. Any help would be greatly appreciated. "Linq Adams via AccessMonster.com" wrote: You don't give your code for closing the form, but I assume it involves checking to see if the current record is, in fact, dirty and forcing the saving of the record before closing the form. This is done to ensure that any validation code be run. This code usually follows the syntax If Me.Dirty Then Me.Dirty = False End If DoCmd.Close I suspect that your form is unbound, and unbound forms don't have a Dirty Property, and thus will pop an error with this code. I understand that this code is used by the command button wizard in ACC2007 when generating a "CLOSE" button. Go into the code window to the OnClick sub for your button and remove the If Me.Dirty Then Me.Dirty = False End If part of the code. -- 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/For...forms/200802/1 |
Thread Tools | |
Display Modes | |
|
|