?
Solved

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

Posted on 2006-06-21
11
Medium Priority
?
695 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
Technology Partners: 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 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 500 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

Technology Partners: 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!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

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