Solved

Access 2003: Compile Error: Invalid Use of Property

Posted on 2006-07-14
7
197 Views
Last Modified: 2012-08-14
I have an Access 2003 database that was created about a year ago.  It it fairly complex and has many forms, tables, etc...  Up until recently one specific form had been working, but now is giving an error when the Save button (a custom button on the form) is clicked.  Below I show the code behind the save button where it is erroring:
------------------------------------------------
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click

    'Save the record:
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Form.Dirty
    'Close the form:
    DoCmd.Close

Exit_cmdSaveRecord_Click:
    Exit Sub

Err_cmdSaveRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdSaveRecord_Click
   
End Sub
-------------------------------------

After entering the essential fields on the form, and clicking the Save button, this error occurs:
Compile Error: Invalid Use of Property

The Form.Dirty property is highlighted upon erroring.

I'm not really clear on what the Form.Dirty property does to begin with & I'm not sure why this seemed to work before, but isn't now.  Any suggestions on how to fix this error would be appreciated.

0
Comment
Question by:sah18
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Author Comment

by:sah18
Comment Utility
I see a little better, though I'm still not quite sure what to do to fix the problem.  This property is also used for the Cancel button on that same form (plus many other forms).  Here is the code for the Cancel button:


Private Sub cmdCancel_Click()
On Error GoTo Err_cmdUndo_Click

    If Me.Dirty Then
     'Undo the changes:
     DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    End If
   
    'Close the form:
    DoCmd.Close

Exit_cmdUndo_Click:
    Exit Sub

Err_cmdUndo_Click:
    MsgBox Err.Description
    Resume Exit_cmdUndo_Click
   
End Sub
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
Comment Utility
Hi sah18,

Form.Dirty identifies whether there have been edits to the fields in the form. If it is true then edits have been made, this allows you to save only when edits have been made and also to check when closing a form or performing some other action as to whether to force (or request) a save.

Use

Me.Dirty = False

In your original function. This will set the form back to "clean" i.e., no edits have been made (because you have just saved them).

Tim Cottee
0
 
LVL 39

Assisted Solution

by:stevbe
stevbe earned 100 total points
Comment Utility
in the first code, delete the    Form.Dirty   line.

Dirt is a property that tells you if any changes have been made and will return true of false so it does not look like there is any reason for you using it.

in the second set of code ... it does make sense ... you weant to see if any changes were made before undoing the data entry.

Steve



0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 100 total points
Comment Utility
Use of Form.Dirty is wrong

As explained by others  

Use one or the other

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Me.Dirty = False       'this saves a record also


Better to use Me.Dirty
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
<aside>

I like using the If Dirty = True Then Dirty = False to force saves because using DOMenuItem or DoCmd.RunCommand does not run in debug because the UI does not have the app focus.

</aside>
0
 
LVL 9

Author Comment

by:sah18
Comment Utility
Thanks for everyone's help!  It seems to be working now -- I made the change to set it to false after the save.  Yeah!!
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
Cool
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now