Solved

VBA; relative path; using OPEN <filename> for Input As #1

Posted on 2006-06-21
11
649 Views
Last Modified: 2010-04-30
I want to open the TNSNAMES.ORA file for input and write its contents to a table.  I can do this if I supply full path (e.g. C:\Oracle92\network\ADMIN\tnsnames.ora) as "filename".  Since I don't always know the exact path, how would I construct the open statement (or the variable "filename") so that it would open the file wherever it is on the PC?
0
Comment
Question by:Shelnutt
  • 5
  • 3
  • 3
11 Comments
 
LVL 5

Expert Comment

by:MageDribble
ID: 16951998
you could have a file selector box (Common Dialog) and have the user manually select the file.  Then use that filename from the file selector as your TNSNAMES.ORA file.

Or are you looking for the program to search the harddrive and look for the file?
0
 

Author Comment

by:Shelnutt
ID: 16952055

Thanks for the quick response.  I am looking for the program to search the harddrive and look for the file.  Users would be totally lost as to where to even begin looking.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 16952173
What application is the VBA in?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 5

Expert Comment

by:MageDribble
ID: 16952266
you can do a recursive file search by extension.  The code is provided at the link.  You can alter the code to search for the entire filename.  

How are you going to handle multiple filenames on a single disk drive?
0
 
LVL 5

Expert Comment

by:MageDribble
ID: 16952270
0
 
LVL 5

Expert Comment

by:MageDribble
ID: 16952304
here is some code for recursive file searching in VB 6:

http://www.freevbcode.com/ShowCode.asp?ID=6979
0
 

Author Comment

by:Shelnutt
ID: 16952675
>What application is the VBA in?
Thanks, I am using MSAccess.
Code at the link looks like more than I need but maybe not!  
>How are you going to handle multiple filenames on a single disk drive?
Plan is to err out if more than one found.
0
 
LVL 5

Expert Comment

by:MageDribble
ID: 16953375
the second link is probably the best link for you.  VB 6 is basically the same as Access VBA.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 125 total points
ID: 16953577
You can use the built-in FileSearch Object:

Sub FindFile()
    Dim i As Integer
   
    With Application.FileSearch
        .NewSearch
        .LookIn = "C:\"
        .SearchSubFolders = True
        .Filename = "TNSNAMES.ORA"
        .MatchTextExactly = True
            If .Execute() > 0 Then
            MsgBox "There were " & .FoundFiles.Count & _
                " file(s) found."
            For i = 1 To .FoundFiles.Count
                MsgBox .FoundFiles(i)
            Next i
        Else
            MsgBox "There were no files found."
        End If
    End With
End Sub
0
 

Author Comment

by:Shelnutt
ID: 16953682
Thanks to everyone who responded.  The last answer from "GrahamSkan" is the one I needed.  I believe I will be able to complete what I started with that.

Please award points to Graham.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 16953823
Thanks. Good luck with the rest of your project.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

777 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