sah18
asked on
Access 2003: Compile Error: Invalid Use of Property
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.
--------------------------
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<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>
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>
ASKER
Thanks for everyone's help! It seems to be working now -- I made the change to set it to false after the save. Yeah!!
Cool
ASKER
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