T
Tru
Here is what I am trying to do (below is the code)
I have a Option Group with two choices "yes and no" that is associated with
a subform. If "yes" is selected then the subform is enabled and the user can
enter records into the subform. If "no" is selected the subform continues to
be disabled.
The problem is when the user have entered records into the subform and now
decides to select "no". When the users selects "no" I prompt them with a
message box explaining to them that if they continue all the records will be
deleted in the subform.
I think the problem is that I am trying to open a recordset that is already
opened by the subform and this is the error message, "Error 13".
I appreciate the help.
Dim Cancel As Integer
Dim MyDb As Database, MySet As Recordset
Set MyDb = DBEngine.Workspaces(0).Databases(0)
Set MySet = MyDb.OpenRecordset("fqryCYFIHSPFactors")
If optSafetyFactors.Value = 1 Then
subSPFactors.Enabled = True
Else
Response = MsgBox("[Safety Concerns]" & NewLine _
& "Changing the above field will result in deleting all of" & NewLine _
& "the safety factors, do you wish to continue?", vbYesNo +
vbExclamation, "Trubase")
If Response = vbNo Then
Me.optSafetyFactors.Value = 1
Cancel = True
Else
With MySet
If .RecordCount > 0 Then
.MoveFirst
Do
.Delete
'Without this MoveNext, ADO would continually
'try to delete the same row, the first one
.MoveNext
Loop Until .EOF
End If
End With
MySet.Close
MyDb.Close
'Need this to requery and save the record before disabling
'the SubForm
Me.Requery
subSPFactors.Enabled = False
End If
End If