Run Time Error

G

Greg Staley

Can someone tell me why I'm getting a run time error 2455 here?

Private Sub cboFilterDate_AfterUpdate()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If
If IsNull(Me.cboFilterDate) Then
Me.FilterOn = False
Else
strWhere = "date=" & _
Format(Me.cboFilterDate, "\#mm\/dd\/yyyy\#")
Me.Filter = strWhere
Me.FilterOn = True
End If

End Sub

This is an attempt to use a combo ox to locate records that I can update on
a form.

Greg
The Always Access Confused
 
E

Emilia Maxim

Greg Staley said:
Can someone tell me why I'm getting a run time error 2455 here?

Private Sub cboFilterDate_AfterUpdate()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If
If IsNull(Me.cboFilterDate) Then
Me.FilterOn = False
Else
strWhere = "date=" & _
Format(Me.cboFilterDate, "\#mm\/dd\/yyyy\#")
Me.Filter = strWhere
Me.FilterOn = True
End If

End Sub

Greg,

the Dirty property of a form is read only, you cannot (re)set it. It
shows if there is some unsaved change in the record. If it's true, you
can either save the record in code instead of Me.Dirty = False or you
can display a message and leave the sub without doing anything with
filtering:

If Me.Dirty Then
MsgBox "Unsaved changes!", vbOKOnly
Else
If IsNull(Me.cboFilterDate) Then
Me.FilterOn = False
Else
...
End If
End If

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
A

Allen Browne

Dirty was read-only in Access 2, but has been writable since A95.

Setting Dirty to True is better than the alternatives:
- RunCommand acCmdSaveRecord works only if the form has focus.
- DoMenuItem ... (as generated by the wizard) is worse still.
- Me.Refresh is useless as it generates no error if the save fails.

If the record cannot be saved for some reason (e.g. required field not
filled, or you cancelled Form_BeforeUpdate), you may receive an error
message saying that VBA cannot set the Dirty property. The message does not
mean the property is read-only, but that the attempt to set it failed.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

"Emilia Maxim" replied in message
news:[email protected]...
 
E

Emilia Maxim

Allen Browne said:
Dirty was read-only in Access 2, but has been writable since A95.

Setting Dirty to True is better than the alternatives:
- RunCommand acCmdSaveRecord works only if the form has focus.
- DoMenuItem ... (as generated by the wizard) is worse still.
- Me.Refresh is useless as it generates no error if the save fails.

If the record cannot be saved for some reason (e.g. required field not
filled, or you cancelled Form_BeforeUpdate), you may receive an error
message saying that VBA cannot set the Dirty property. The message does not
mean the property is read-only, but that the attempt to set it failed.

Allen,

thank you very much for the info. When I answered the message, I had
the Windows with A97 up, and the Help states, it's a read only
property. As I never had a need to set it, I simply believed what I
read :-( Until now I thought only the A2K help is miserable...

And hey, I see now the A2K Help states the same:
"This property is write protected and only available in a macro or in
Visual Basic."

Welll, no comment...

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top