ErrorMessage when file is missing

  • Thread starter Thread starter reidarT
  • Start date Start date
R

reidarT

Dim Kildefil as object

Kildefil = "H:\dbBil\dbBil.mdb"

if not Dir(Kildefil)) Then
else
Msgbox("Can't find file!",msgboxstyle.information,conMelding)
end if

I get this error when file is missing.

Change form string to type Long is not legal.
regards
reidarT
 
Dim Kildefil as object
Kildefil = "H:\dbBil\dbBil.mdb"

if not Dir(Kildefil)) Then
else
Msgbox("Can't find file!",msgboxstyle.information,conMelding)
end if

I get this error when file is missing.

Change form string to type Long is not legal.
regards
reidarT

The Dir() function returns a string and the syntax you used
*may* be trying to coerce the string to a long. Try this
syntax:

If Dir(Kildefil) <> "" Then
' Found the file
Else
' File not found
Msgbox("Can't find file!",msgboxstyle.information,conMelding)
End If

HTH,

J Edgar
 
reidarT said:
Dim Kildefil as object

Kildefil = "H:\dbBil\dbBil.mdb"

if not Dir(Kildefil)) Then
else
Msgbox("Can't find file!",msgboxstyle.information,conMelding)
end if

I get this error when file is missing.

*Never* use 'Dir' to check if a file exists. Use 'System.IO.File.Exists'
instead.
 
Reidar,

In VBNet are easier functions for that.

If Not file.exist("H:\dbBil\dbBil.mdb") then; is the one I like the most,
however there is as well

If Fileinfo.exist(("H:\dbBil\dbBil.mdb")

The last class can give a lot of information about files as well.

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top