add new record to ADO recordset via stored proc
Hi all,
I am converting a split DAO .mdb to SQL/ADO/.adp.
In the original .mdb, there is a main form with 4 subforms. each of these subforms contain records that correlate to the main form. I had to simplify the original form recordsources to make them writable (they used multiple joins before) and transform those recordsources to stored proc's. I am having trouble writing to one of these recordsets still however, particularily in the re-sequencing if the records after .addnew method. Thanks in advance for any insight. see below code :
(original DAO .mdb code)
Private Sub AddRecordButton_Click()
Dim rst As Recordset, CurrentRecord As Long, varBookmark As Variant
If (IsNull(Me.Parent.CNPickCombo)) Then
MsgBox ("Cannot insert a record into a use case without selecting a change.")
Else
CurrentRecord = Me!SequenceNumber
Set rst = Me.RecordsetClone
If (rst.BOF = False And rst.EOF = False) Then
rst.MoveFirst
rst.Move CurrentRecord - 1
Do Until rst!SequenceNumber = rst.RecordCount
rst.Edit
rst!SequenceNumber = rst!SequenceNumber + 1
rst.Update
rst.MoveNext
Loop
rst.Edit
rst!SequenceNumber = rst!SequenceNumber + 1
rst.Update
rst.AddNew
rst!OwnerUseCaseID = Forms!UCStepsMainForm!UseCaseID
rst!SequenceNumber = CurrentRecord
If (Me.Parent.Baselined) Then
rst!Modified = True
rst!CurrentCR = Me.Parent.CNPickCombo
End If
rst.Update
rst.Close
Me.Requery
Set rst = Me.RecordsetClone
rst.FindFirst "SequenceNumber = " & CurrentRecord
Me.Bookmark = rst.Bookmark
rst.Close
Else
rst.Close
End If
End If
End Sub
(Current ADO .adp code)
Private Sub AddRecordButton_Click()
Dim rst As New ADODB.Recordset
Dim CurrentRecord As Long
If (IsNull(Me.Parent.CNPickCombo)) Then
MsgBox ("Cannot insert a record into a use case without selecting a change.")
Else
CurrentRecord = Me!SequenceNumber
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
Set rst = Me.Recordset
If (rst.BOF = False And rst.EOF = False) Then <---PROBLEM HERE?
rst.MoveFirst
rst.Move CurrentRecord - 1
Do Until rst!SequenceNumber = rst.RecordCount + 1
rst!SequenceNumber = rst!SequenceNumber + 1
rst.Update
rst.MoveNext
Loop
rst!SequenceNumber = rst!SequenceNumber + 1
rst.Update
rst.AddNew
rst!OwnerUseCaseID = Forms!UCStepsMainForm!UseCaseID
rst!SequenceNumber = CurrentRecord - 1
If (Me.Parent.Baselined) Then
rst!Modified = True
rst!CurrentCR = Me.Parent.CNPickCombo
End If
rst.Update
rst.Close
Me.Requery
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
Set rst = Me.Recordset
rst.Find "SequenceNumber = " & CurrentRecord
'Me.Bookmark = rst.Bookmark
Else
End If
End If
End Sub
|