RESOLUTION
One way to avoid this problem is to set the Enabled property of all
controls bound to an RDC to False. If edits are desired, then a command
button to enable the controls can be added to the form. The controls would
be disabled when the edit is committed or canceled.
Another way to avoid this problem is to add code similar to that below to
the Validate event procedure for each RDC:
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 this problem is being encountered because the RDC's LockType property is
set to rdConcurReadOnly, then there is a simpler workaround than the above.
Choose another value for the LockType property, and add the following code
to the RDC's Validate event:
If (Action = rdActionUpdate) Then Action = rdActionCancelUpdate
This problem can also be avoided by using the Microsoft ADO Data Control.