Solved

Access 2003: Compile Error: Invalid Use of Property

Posted on 2006-07-14
7
201 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
ID: 17107433
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
ID: 17107452
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
ID: 17107461
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 100 total points
ID: 17107475
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
ID: 17107546
<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
ID: 17107644
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
ID: 17107788
Cool
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

685 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