Solved

Access 2003: Compile Error: Invalid Use of Property

Posted on 2006-07-14
7
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

738 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