How to error trap when opening a DB via OpenDatabase

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If the following statement

Set TestDB = OpenDatabase ("C:\TempFolder\Destination.mdb")

fails, I would like to output a message.
 
One alternative would be something like the following:

Function OpenDatabase()
Dim TestDB As Database

On Error GoTo Errorhandler
Set TestDB = OpenDatabase("H:\db7.mdb")

'Other code here

Exit_Function:
Set TestDB = Nothing

Exit Function

Errorhandler:
If Err.Number = 3024 Then
MsgBox "Could not open the specified database", vbCritical, "Error"
Resume Exit_Function
End If
End Function

Error number 3024 is the error generated when the specified file cannot be
found.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


If the following statement

Set TestDB = OpenDatabase ("C:\TempFolder\Destination.mdb")

fails, I would like to output a message.
 
Back
Top