?
Solved

How to use Open statement to open file selected from drivelist and filelist? Pls help!!!

Posted on 2003-02-26
9
Medium Priority
?
159 Views
Last Modified: 2010-05-01
Hi..I try to use the Open statement to open a file that is selected from the drive,dir and file list.However I get an error "File not found" but in actual fact the file does exist.This is what I do:

Private Sub FileERT_Click()
Dim i%, textline$, k1$, a1$, d1$

d1 = DirERT.Path & " \ " & FileERT.FileName

i = FreeFile
Open "d1" For Input Shared As #i   <--error occurs here

Do While Not EOF(i)
 Line Input #i, textline    'reading each line
k1 = Mid(textline, 2, 2)
a1 = Right(textline, 2)



Loop

Close #i
End Sub

If i were to replace the line where error occurs with this:
Open "D:\sample_ERT\HC05C8A.txt" For Input Shared As #i

then it is ok. Directory is the same as d1.

Pls help!!
0
Comment
Question by:VivienW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 11

Expert Comment

by:Steiner
ID: 8023712
Your problem are the spaces around "\". Use no spaces, only "\":

d1 = DirERT.Path & "\" & FileERT.FileName



Greets
Steiner
0
 

Author Comment

by:VivienW
ID: 8023755
I've taken away the spaces but it still does not work.Is it case sensitive?
Because as I step thru debug,d1=d:\sample_ERT\HC05C8A.txt
The only difference is the D: and d:. If yes, how do I change it to uppercase.This is because from the drive list it is in smallcase.
Thanks
0
 
LVL 1

Accepted Solution

by:
Belfry earned 200 total points
ID: 8023824
the problem is: you used quotation marks around "d1", kill the quotation marks, you'll succeed.

Open d1 For Input Shared as #i

try it, good luck!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:muskad202
ID: 8023849
the error is u are doing
---------------
Open "d1" For Input Shared As #i  
--------------------

when it should be
----------------------
Open d1 For Input Shared As #i  
-----------------------

no quotation marks !!!
0
 
LVL 2

Expert Comment

by:muskad202
ID: 8023851
oops belfry...we posted at around the same time  :)
0
 
LVL 3

Expert Comment

by:Rem
ID: 8023863
Open "d1" For Input Shared As #i '<--error occurs here
Open d1 For Input Shared As #i '<--error should not occur

0
 
LVL 3

Expert Comment

by:Rem
ID: 8023869
we all seem to post at the same time. LOL
0
 
LVL 11

Expert Comment

by:Steiner
ID: 8024237
Why didn't I see that?????
0
 
LVL 3

Expert Comment

by:Rem
ID: 8024294
;-))
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question