>I'm stumped....
>In the code below... why is it that the "couldn't find file" error is
>getting through the error check when I (on purpose) don't have the mdb
>file in the app folder?
>Yet, when I uncomment the commented lines, it gives me a msgbox as
>expected??
>Private Sub Form_Load()
> On Error GoTo ErrorHandler
> 'If Right(App.Path, 1) = "\" Then
> ' Open App.Path & "notexist.txt" For Input As #1
> ' Else
> ' Open App.Path & "\notexist.txt" For Input As #1
> ' End If
> If Right(App.Path, 1) = "\" Then
> datGallery.DatabaseName = App.Path & "GALLERY.MDB"
> Else
> datGallery.DatabaseName = App.Path & "\gallery.mdb"
> End If
>Exit Sub
>ErrorHandler:
>MsgBox Err.Number & " " & Err.Description
>End Sub
>Tony!
You will not get an error from the uncommented lines until you try to
do something with datGallery. Just assigning the invalid path to the
database property does not cause the path to be checked. If you want
to check for the existence of gallery.mdb in this routine you should
check if the file exists using your favourite of the many methods
which have been suggested in this newsgroup. A Google group search of
file +exists will probably give you all of them. Meanwhile, here's
mine:
Function PathCheck(ByVal vsPath As String, ByVal vbTellUser As
Boolean) As Boolean
' Check that the file vsPath is accessible.
Dim bFileExists As Boolean
On Error Resume Next
bFileExists = (Dir(vsPath, vbNormal) <> "")
If Err.Number <> 0 Then
bFileExists = False
End If
On Error GoTo 0
If Not bFileExists And vbTellUser Then
Screen.MousePointer = vbNoDrop
MsgBox "Cannot locate file " & vsPath, vbOKOnly Or vbCritical
Screen.MousePointer = vbDefault
End If
PathCheck = bFileExists
End Function