simple?? Error checking

simple?? Error checking

Post by Tony » Mon, 14 Jul 2003 14:42:17



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!

 
 
 

simple?? Error checking

Post by Gunter Schmid » Mon, 14 Jul 2003 17:17:26




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

 
 
 

simple?? Error checking

Post by Mike William » Mon, 14 Jul 2003 18:16:15



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

 
 
 

simple?? Error checking

Post by David Segal » Mon, 14 Jul 2003 22:57:26



>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

 
 
 

simple?? Error checking

Post by Frank Ad » Tue, 15 Jul 2003 00:16:36




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

 
 
 

1. Simple Check Constraint Condition Question...

Hello.

I have a simple table example;

create table events (
                event_year    varchar2(4) not NULL,
                event_date    date not NULL
)

What I want is to constrain event_year to be equal to the
year portion of event_date. Event_year is entered as a YYYY value.

I think that this is close to what I want in the constraint.

event_year = to_date(event_date, 'YYYY')

However I get a ORA-2436: date or system variable wrongly specified
in CHECK constraint.

Does this mean that I should be translating the date to a string?

STeve
-----EOT

2. Help with error 18001

3. Simplest way to check connection

4. US:CA:Glendale:Oracle Programmer Needed

5. A simple question on check box

6. Simple Database Checking?

7. SQL7, SIMPLE SIMPLE SIMPLE question

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

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

10. undocumented feature/bug WITH CHECK CHECK

11. DELETE does not check CHECK constraint