Solved

Access 2003: Compile Error: Invalid Use of Property

Posted on 2006-07-14
7
200 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…

791 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