Solved

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

Posted on 2006-06-21
11
643 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now