Solved

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

Posted on 2006-06-21
11
638 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
Comment Utility
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
Comment Utility

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
Comment Utility
What application is the VBA in?
0
 
LVL 5

Expert Comment

by:MageDribble
Comment Utility
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
Comment Utility
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 5

Expert Comment

by:MageDribble
Comment Utility
here is some code for recursive file searching in VB 6:

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

Author Comment

by:Shelnutt
Comment Utility
>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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. Good luck with the rest of your project.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

762 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

15 Experts available now in Live!

Get 1:1 Help Now