Running store procedures

R

Roy Goldhammer

Hello there

I use ADP. when i run Stored procedures i use ADODB.Command object to run
them on code.

If an error occured on the stored procedure on sql server the action won't
happen and vb does't get any type of error.

Is there a way to transfare the error to vb so i can take care of it on the
code?

any help would be useful
 
S

SA

Roy:

Yes, you can capture the ADO based error, but you have have your code
running in a class module rather than a regular module (remember that form
and report modules are class modules as well as db wide standard class
modules,) because only classes can have events (e.g. an error event)
associated with them. In the class:

You dimension your connection on the class' general declares page so its
visible across the class, using the WithEvents key words as in:

Dim WithEvents Conn As ADODB.Connection

Initialize the connection object in the class' Initialize event.

Then you add an event procedure like this to your class:

Private Sub conn_ExecuteComplete(ByVal RecordsAffected As Long, _
ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pCommand As ADODB.Command, _
ByVal pRecordset As ADODB.Recordset, _
ByVal pConnection As ADODB.Connection)
'check for errors during the asynchronous operation
If (adStatus = adStatusErrorsOccurred) Then
MsgBox "Error # " & pError.Number & vbCrLf & pError.Description
End If
End Sub

This is also lightly covered in the help file under the Events of the
Connection object and more completely in the Microsoft Knowledgebase.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top