dumb question, but i've forgotten

J

James

I've got a Class Module "DBAdmin" and a form "Administration". I have a
public string variable in the dbadmin and i want to use it in
administration msgbox.

'This is the Administration form
Private Sub cmdImportOfferings_Click()
Dim dbUtils As New DBAdmin

If dbUtils.ImportXML("C:\Offerings Project\offerings.xml") Then
MsgBox "Offerings XML successfully imported"
Else
'it doesn't lke the next line
MsgBox DBAdmin.ErrorMsg
End If

Set dbUtils = Nothing
End Sub


-----------------------------
'this is the DBAdmin Class Module


Dim ErrorMsg As String
Public Function ImportXML(FileName As String) As Boolean
On Error GoTo Error_Handler

'Dim appAccess As New Access.Application

'appAccess.ImportXML DataSource:=fileName,
ImportOptions:=acStructureAndData
Application.ImportXML FileName, acStructureAndData

ImportXML = True
Exit_Method:
Set appAccess = Nothing
Exit Function

Error_Handler:
ImportXML = False
ErrorMsg = Err.Description
GoTo Exit_Method
End Function



Thanks.
 
G

Graham R Seach

James,

Add a property to the class:
Public Property Get ErrMsg() As String
ErrMsg = ErrorMsg
End Property

But I think you'd be better server by percolating the error back to the
calling procedure. You can do that in the class using either CVErr(), a
public event, or by using Err.Raise. Using the public event scenario would
required declaring the class object variable using WithEvents, and trapping
the event in the form. Using the Err.Raise method requires you to use 'On
Error Goto 0' in the class, and trapping the error in the form. The code I
supplied, however, is the simplest option.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 

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