-
Hi
I want to use some classes in an Active X Dll that would represent tables in an Acess database
This dll would then be accessed from my app meaning that that the data would be seperated from the front end
What I am not sure about though is how to handle errors
If I placed addnew, edit or update methods in the class would they have to be made functions returning a boolean value rather than normal sub methods
the code from the front end would then be
set ObjSales = new SalesDll.clsSales
if objsales.addnew then
' add new items
if objsales.update then
msgbox "all ok "
else
msgbox "Errors occured"
end if
Therefore what I need to know is how to communcicate errors betweeen the dll and the calling form
many thanks
Mark
-
Use events to pass back information to the calling application:
(Using you code form below)
Code:
'In the declarations section
Public Event UpdateSuccessful()
Public Event UpdateError(plngErrorNumber as Long, pstrErrDesc as String)
'In the
if objsales.addnew then
' add new items
if objsales.update then
RaiseEvent UpdateSuccessful
else
RaiseEvent UpdateError(Err.Number, Err.Description
end if
Then, when you declare that object in the application, you declare it using the WithEvents keyword, remembering that it must be a module level declaration eg:
Code:
Private WithEvents mobjSales as clsSales
Alternatively, you can use Err.Raise to pass the error out (but this way you MUST catch the error. Using Withevents means the error is caught in the DLL, not the app.
- gaffa