Solved

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

Posted on 2006-06-21
11
655 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

839 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