Thom
Sep 22nd, 2000, 09:51 AM
OK, when I raise an error in the following code, the Recordset seems to be LOST in the Test form!
Private Sub cmdSaveTest_Click()
On Error GoTo ErrHandler
Dim cnn1 As ADODB.Connection
Dim Counter As Integer
Dim sSQL3 As String
Set cnn1 = New Connection
cnn1.Open g_strConnection
'BEGIN TRANSACTION!! ******************
cnn1.BeginTrans
If cnn1.State = adStateOpen
Counter = 1 ' for FIRST record!
Rs1.MoveFirst
Do Until Rs1.EOF = True
sSQL3 = "INSERT Into Results(Number, QuestionNumber, UserAnswer) "
sSQL3 = sSQL3 & "VALUES (" & Num & "," & Counter & "," & rs1!Answer & ")"
cnn1.Execute sSQL3, , adExecuteNoRecords
rs1.MoveNext
Counter = Counter + 1
Loop
' NEED TO RAISE AN ERROR TO TEST THIS!!!
Err.Raise 3732
' IF WE GET HERE, ALL's WELL!
cnn1.CommitTrans
Else ' NO STATE OPEN!!
MsgBox "NO CONNECTION!"
cnn1.Close
Rs1.MoveFirst
cmdSaveTest.SetFocus
Exit Sub
End If
ErrHandler:
cnn1.RollbackTrans
MsgBox Err.Number & Err.Description
cnn1.Close
cmdSave.SetFocus
Exit Sub
End Sub
When an error occurs, & I go back to the Test form It's like the Questions & answers have been wiped clean! The last record/question is showing in the form-but none of the others are? Does anyone have any idea why? Is there something in the code above that is deleting the recordset? I'd appreciate any help!
Private Sub cmdSaveTest_Click()
On Error GoTo ErrHandler
Dim cnn1 As ADODB.Connection
Dim Counter As Integer
Dim sSQL3 As String
Set cnn1 = New Connection
cnn1.Open g_strConnection
'BEGIN TRANSACTION!! ******************
cnn1.BeginTrans
If cnn1.State = adStateOpen
Counter = 1 ' for FIRST record!
Rs1.MoveFirst
Do Until Rs1.EOF = True
sSQL3 = "INSERT Into Results(Number, QuestionNumber, UserAnswer) "
sSQL3 = sSQL3 & "VALUES (" & Num & "," & Counter & "," & rs1!Answer & ")"
cnn1.Execute sSQL3, , adExecuteNoRecords
rs1.MoveNext
Counter = Counter + 1
Loop
' NEED TO RAISE AN ERROR TO TEST THIS!!!
Err.Raise 3732
' IF WE GET HERE, ALL's WELL!
cnn1.CommitTrans
Else ' NO STATE OPEN!!
MsgBox "NO CONNECTION!"
cnn1.Close
Rs1.MoveFirst
cmdSaveTest.SetFocus
Exit Sub
End If
ErrHandler:
cnn1.RollbackTrans
MsgBox Err.Number & Err.Description
cnn1.Close
cmdSave.SetFocus
Exit Sub
End Sub
When an error occurs, & I go back to the Test form It's like the Questions & answers have been wiped clean! The last record/question is showing in the form-but none of the others are? Does anyone have any idea why? Is there something in the code above that is deleting the recordset? I'd appreciate any help!