Article ID: 194980
Article Last Modified on 1/9/2003
Private Sub MSRDC1_Validate(Action As Integer, Reserved As Integer)
If Action = rdActionUnload Then
If (MSRDC1.Resultset Is Nothing) Then
UndoEdits Me
Else
If (Not MSRDC1.Resultset.Updatable) Then
UndoEdits Me
End If
End If
End If
End Sub
Also add the following procedure to a standard module:
Sub UndoEdits(frm As Form)
Dim ctl As Control
For Each ctl in frm.Controls
On Error Resume Next
If (TypeName(ctl.DataSource) = "MSRDC") Then
If (Err = 0) Then
ctl.DataChanged = False
ElseIf (Err <> 438) Then
MsgBox "Unexpected error!"
Stop
End If
End If
Next ctl
End Sub
The effect of this code is to cause any changes to data to be ignored when
the form is being closed (rdActionUnload). It is assumed that this is the
desired behavior because the resultset is non-updateable. There are two
pieces of this code worth noting. If the RDC itself is not bound to data,
then it is "non-updateable" with respect to the behavior described in this
article. Also, error 438, "object does not support this property or
method", will occur for any controls that do not support a DataChanged
property. Because this code checks every control on the form, this error is
expected for controls such as command buttons.If (Action = rdActionUpdate) Then Action = rdActionCancelUpdateThis problem can also be avoided by using the Microsoft ADO Data Control.
Keywords: kbprb kbctrl KB194980