Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trap an OpenDatabase Error

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
I am using

Code:
Set dbODBC = wsApp.OpenDatabase("", False, False, sODBC)

to connect to the SQL Server

And just wanted to know how is the best way to check that a connection is made..

Ie.. getting back a True Or False for a successfuil connection rather than gettng the SQL Server Error.

 
Not a lot of choices in Access (that I know of).

I would just add an error handler to your sub.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
have you got an example of the error trapping please?
 
Code:
Public Sub OpenTheDB()

  On Error Goto ErrHandler

  Set dbODBC = wsApp.OpenDatabase("", False, False, sODBC)

  'This prevents you from  falling through to the error handler
  Exit Sub   

ErrHandler:
  MsgBox "Error #" & Err.Number & ": " & Err.Description

End Sub

 
I have no idea if this will work, but it's worth a try...

Check if the LastDllError property of the error object returns something useful, eg:
Code:
ErrHandler:
    MsgBox "Error #" & Err.Number & ": " & Err.Description & vbcrlf & _
           "External error: " & err.LastDllError

Max Hugen
Australia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top