A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Dirty Expression



 
 
Thread Tools Display Modes
  #1  
Old February 4th, 2008, 01:52 AM posted to microsoft.public.access.forms
Rose
external usenet poster
 
Posts: 262
Default 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  
Old February 4th, 2008, 02:38 AM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default 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  
Old February 4th, 2008, 02:36 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default 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  
Old May 1st, 2008, 08:41 PM posted to microsoft.public.access.forms
J. Denby
external usenet poster
 
Posts: 1
Default 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


  #5  
Old May 1st, 2008, 11:49 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Dirty Expression

No. This has not been fixed, and is not likely to be (given how long the
problem has existed.)

Just add the lines to the code.

--
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.

"J. Denby" J. wrote in message
...
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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.