Class debugging

J

Jesse Aviles

I'm having trouble with the Err.raise. I created a class (I'm using Access
XP Developer's Handbook and VBA Developer's Handbook as guides) and on the
error handling procedure placed the following line of text:
Err.Raise Err.Number, Err.Source, Err.Description

The way I read the books and VBA online help, I was expecting that when an
error ocurred, the error handler from the calling code would get the
information provided by Err.Raise. Instead I see the regular VBA Error box
(the one with the debug and end buttons) with the following message:
Error 438: Object doesn't support this property or method.

If I click on debug, VBA points me to the calling code error handler. The
code, generally, in my error handler is as follows:
MsgBox "Error " & Err.Num & vbNewLine & Err.Description & vbNewLine &
"In cmdDeleteRecord_Click."
Resume ExitHandler

Can anyone tell me what I'm doing wrong or understanding wrong?

Thanks,
Jesse Aviles
j a v i l e s @ v e l o x i u s . c o m
 
B

Brendan Reynolds

<quote>
MsgBox "Error " & Err.Num & vbNewLine & Err.Description & vbNewLine &
</quote>

That should be 'Err.Number' not 'Err.Num' - when you get the error message
that the 'object doesn't support this property or method', the object in
question is the Err object, and the property or method that it doesn't
support is 'Num'.
 
J

Jesse Aviles

Although on the post is wrtitten as Err.Num, in the code is Err.Number. The
error is coming out eventhough the spelling is correct.
 
J

Jesse Aviles

The class represents a record from a table. You can set the field values,
save and delete the record as well as compare two records. This is the code
from the delete function of the class. The error handler is virtually the
same for the other functions in the class. The code works well. I have
used all the functions in the class without trouble.

Public Function DeleteRecord() As Boolean
' Comments :
' Parameters:
' Returns : Boolean -
' Created : 11 Nov 2005 06:40 JA
' Modified :
' --------------------------------------------------

On Error GoTo ErrorHandler
Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset
'Check if there are associated records that need deleting
rst.Open "SELECT * FROM tblProposalItems WHERE lutxtPropID = '" &
Me.Propuesta & "'", _
Application.CurrentProject.Connection, , adLockPessimistic

If rst.EOF Then 'No records in tblProposalItems
rst.Close
Else
Do While Not rst.EOF 'Records found in tblProposalItems. Start
deleting.
rst.Delete
rst.Update
Loop
rst.Close
End If

'Delete proposal
rst.Open "SELECT * FROM tblPropuesta WHERE txtPropID = '" & Me.Propuesta
& "'", _
Application.CurrentProject.Connection, , adLockPessimistic

rst.Delete
rst.Update
rst.Close
Set rst = Nothing
DeleteRecord = True

ExitHandler:
Exit Function

ErrorHandler:
DeleteRecord = False
Err.Raise Err.Number, Err.Source, Err.Description
Resume ExitHandler

End Function


This is the code from the form. The Delete function of the class is called
by clicking on a command button. The problem ocurred when I tried to delete
a record that was already deleted.


Private Sub cmdDeleteRecord_Click()
' Comments :
' Parameters:
' Created : 10 Nov 2005 07:11 JA
' Modified :
' --------------------------------------------------

On Error GoTo ErrorHandler
Dim strMessage As String
Dim intButtons As Integer
Dim strTitle As String
Dim objPropuesta As Propuesta

strMessage = "¿Quieres borrar el récord?"
intButtons = vbYesNo + vbQuestion
strTitle = "Borrar Récord"

Select Case MsgBox(strMessage, intButtons, strTitle)
Case vbYes
Set objPropuesta = New Propuesta
objPropuesta.Propuesta = Me.txtPropID
If objPropuesta.Load Then 'Chequear si la forma existe antes
de borrarla
If objPropuesta.DeleteRecord Then
Me.Caption = "Añada o seleccione una propuesta"
bolNewPropuesta = True
Else
MsgBox "No se puede borrar la propuesta en este
momento."
End If
Else 'Eliminar las entradas hechas
Call VaciarForma
Me.Caption = "Añada o seleccione una propuesta"
bolNewPropuesta = True
End If
Set objPropuesta = Nothing
Case vbNo
'Salir sin hacer nada
End Select

ExitHandler:
Exit Sub

ErrorHandler:
MsgBox "Error " & Err.Num & vbNewLine & Err.Description & vbNewLine &
"In cmdDeleteRecord_Click."
Resume ExitHandler

End Sub


Thanks.
 
J

Jesse Aviles

Mr. Reynolds:
Your first response was right. On the forms, it read Err.Num and that was
the actual problem. Once I changed it to Err.Number, the error generated by
the class was passed to the form and I could see the actual error. The
generic error handling code that I have was written with this error (my
mistake) and I had to change it in so many places. You have been very
helpful, thanks!
 
J

Jesse Aviles

Mr. Reynolds:
Your first response was right. On the forms, it read Err.Num and that was
the actual problem. Once I changed it to Err.Number, the error generated
by the class was passed to the form and I could see the actual error. The
generic error handling code that I have was written with this error (my
mistake) and I had to change it in so many places. You have been very
helpful, thanks!
 
B

Brendan Reynolds

From the error handler in your cmdDeleteRecord_Click() procedure ...

<quote>
MsgBox "Error " & Err.Num & vbNewLine & Err.Description & vbNewLine &
</quote>

If this is the actual code, then it would appear that I was right the first
time?
 
B

Brendan Reynolds

I posted that just before I saw your most recent post in the thread. Glad to
hear it worked out for you.
 
M

mmellring

Jesse Aviles said:
I'm having trouble with the Err.raise. I created a class (I'm using Access
XP Developer's Handbook and VBA Developer's Handbook as guides) and on the
error handling procedure placed the following line of text:
Err.Raise Err.Number, Err.Source, Err.Description

The way I read the books and VBA online help, I was expecting that when an
error ocurred, the error handler from the calling code would get the
information provided by Err.Raise. Instead I see the regular VBA Error box
(the one with the debug and end buttons) with the following message:
Error 438: Object doesn't support this property or method.

If I click on debug, VBA points me to the calling code error handler. The
code, generally, in my error handler is as follows:
MsgBox "Error " & Err.Num & vbNewLine & Err.Description & vbNewLine &
"In cmdDeleteRecord_Click."
Resume ExitHandler

Can anyone tell me what I'm doing wrong or understanding wrong?

Thanks,
Jesse Aviles
j a v i l e s @ v e l o x i u s . c o m
 

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