simple?? Error checking 
Author Message
 simple?? Error checking

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!



Thu, 29 Dec 2005 13:42:17 GMT
 simple?? Error checking



Quote:
> 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!

What do you want to accomplish?

app.path always comes without "\"

I would do something like this

datGallery.DatabaseName = App.Path & "\gallery.mdb"

if dir(datGallery.DatabaseName)<> "" then
    Open Database
else
    create database
endif

--------------------------

if not sure about the \ you can have a function

Function FormatPfad(ByVal Pfad As Variant) As String
' -------------------------------------------------------------------
' Funktion: Gibt Pfad so aus, dass immer ein "\" am Ende steht
' changes path to make sure "\" is at end
'
' Parameter: keine
'
' Rckgabewerte: keine
'
' letzte ?nderung: 10.12.2002
' -------------------------------------------------------------------

    If Right$(Pfad, 1) <> "\" Then Pfad = Pfad + "\"
    FormatPfad = Pfad

End Function

datGallery.DatabaseName = FormatPfad(App.Path)  & "gallery.mdb"

Gunter



Thu, 29 Dec 2005 16:17:26 GMT
 simple?? Error checking

Quote:

> app.path always comes without "\"

Not if it happens to be the root directory, in which case you will get the
trailing backslash ("C:\" for example). People don't usually install your
app to the root directory of course, but they could do so if they wanted to.
It's always best to check.

Mike



Thu, 29 Dec 2005 17:16:15 GMT
 simple?? Error checking

Quote:

>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



Thu, 29 Dec 2005 21:57:26 GMT
 simple?? Error checking


Quote:
>>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
>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.

Strange. I get an error straight up. Perhaps a version thing ?
I'm running the latest DB engine here, AFAIK. DAO3.6

--

Regards, Frank



Thu, 29 Dec 2005 23:16:36 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. Simple Check Constraint Condition Question...

2. Simplest way to check connection

3. A simple question on check box

4. Simple Database Checking?

5. SQL7, SIMPLE SIMPLE SIMPLE question

6. Has anyone seen this error - DISTRIB.EXE - Version Check Error

7. I/O error 23(Data error (cyclic redundancy check)

8. undocumented feature/bug WITH CHECK CHECK

9. DELETE does not check CHECK constraint

10. Checking Checked items in Listview

11. Checking check box status

12. Designer 6 check in and check out


 
Powered by phpBB® Forum Software