By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

ErrorMessage when file is missing

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> 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
Nov 21 '05 #2

P: n/a
"reidarT" <re****@eivon.no> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a
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
"reidarT" <re****@eivon.no>
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

Nov 21 '05 #4

P: n/a
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
If Fileinfo.exist(("H:\dbBil\dbBil.mdb")

'Exists' is an instance method of 'FileInfo'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5

P: n/a
Herfried,

I was already waiting for this message.

:-)

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.at>
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
If Fileinfo.exist(("H:\dbBil\dbBil.mdb")

'Exists' is an instance method of 'FileInfo'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.