Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Exists - and the Dir Function

Status
Not open for further replies.

tolan

IS-IT--Management
Jun 9, 2001
15
GB
Hi

I've been hitting my head on this one for a few hours ... I want to check whether a file exists, and once that has been established either save a file into location a or b.

Below is my code (I'm just using message boxes at the moment to ensure it works correctly, rather than saving). However the message boxes that appear aren't correct, and the variations that have been displayed are dependent on whether I place a space in between the quotes on the line that reads 'If MyFile <> &quot;&quot; Then'

I've been renaming the 'c:\connect.txt' file to test for different variations but I haven't had any luck!

Where am I going wrong, I've written other bits and bobs but can't see what I'm doing wrong with this! Any ideas gratefully received?

Tolan

=-=-=-==-=-=-=
Sub CommandButtonClick()

Dim MyFile as String

MyFile = Dir(&quot;C:\connect.txt&quot;)
If MyFile <> &quot;&quot; Then
MsgBox &quot;File Exists.&quot;
Else
MsgBox &quot;No such file&quot;
End Sub

=-=-=--=-=-=-=-=-
 
Thanks for the response, sorry but the code has got the 'end if' in it, I just forgot to type it in on my posting! So the code actually looks like this:

=-=-=-==-=-=-=
Sub CommandButtonClick()

Dim MyFile as String

MyFile = Dir(&quot;C:\connect.txt&quot;)
If MyFile <> &quot;&quot; Then
MsgBox &quot;File Exists.&quot;
Else
MsgBox &quot;No such file&quot;
End if
End Sub

=-=-=--=-=-=-=-=-

Any other ideas?
 
Hi, T,

Your code works just fine. I don't have a clue. X-) Skip,
metzgsk@voughtaircraft.com
 
Hi, thanks for helping on this. I've added your suggestions but it still doesn't want to play ball!

I've even cut and paste the code from M$ web site into my code and and the same thing happens


Should I be declaring something somewhere or is there something obvious that I'm overlooking?

Grateful for any ideas!

Tolan
 
OK this is so strange, I took exactly the same code and placed it on my networked PC rather than the laptop and the code works fine..... therefore there's an issue with the laptop..... bizarre, I've got no idea what though!!

T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top