Visual Basic > API and Miscellaneous
Returning helpful information from failed CreateObject
Returning helpful information from failed CreateObject Below is a useful function for obtaining error information about failed CreateObject calls... 'Purpose : Wrapped function around CreateObject which returns a helpful error message. ' i.e. not the useless ActiveX can't create component error. 'Inputs : sClass The class or progID of the object to create. ' sServer The server name to create the object on (defaults to local machine). 'Outputs : N/A Function CreateObject2(sClass As String, Optional sServer As String) As Object On Error GoTo ErrFailed If Len(sServer) = 0 Then Set CreateObject2 = CreateObject(sClass) Else Set CreateObject2 = CreateObject(sClass, sServer) End If Exit Function ErrFailed: Msgbox "Error failed to create ActiveX component... " & _ vbNewLine & "Component Name: " & IIf(Len(sServer), sServer & ".", "") & sClass & _ vbNewLine & "Error: " & Err.Description, vbCritical End Function
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows