Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access 2003: Compile Error: Invalid Use of Property

Posted on 2006-07-14
7
Medium Priority
?
206 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 1200 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 400 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 …
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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 …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

879 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