Get Database Path from path stored in .txt file?

Posted on 2004-11-14
Last Modified: 2010-04-23
I have an access database and I have a .txt file that has the path stored in it.
The file is already in C:/Program Files/ThisOtherProgram/Config.txt and it contains this line;  4,Z:\DataPath\Data.mdb
This is the path that I would like my program to access the database with because depending on which computer you use the path may be different to my database.

How would I open this file, find "4, X:\ThePath\To\The\Database" and use that for my database connection location when my program loads?

Thanks for any code  or help you can provide
Question by:Matrix1000
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Hi Matrix1000,

    Is the line with the database information:


    going to be the first line in the text file? ...or do we need to "find" it as you said by looking for the "4," as the beginning of the line?

    LVL 1

    Author Comment

    Right now it is the first line in the file but potentially there could be something else as the first line (like setting 1,2 and 3) So it might be good to look for the "4"
    LVL 25

    Accepted Solution

    something like this

    Dim sr As System.IO.StreamReader = New System.IO.StreamReader("C:/Program Files/ThisOtherProgram/Config.txt")
            Dim line As String
            Dim path As String
            line = sr.ReadLine()
            Do While Not line Is Nothing

                If line.StartsWith("4,") Then
                    path = line.Substring(2).Trim
                End If
                line = sr.ReadLine()

    path should now hold your database path
    LVL 1

    Author Comment

    Thanks!   How would I use "path" in the connection string...

            Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Registry Path=;Data Source=""C:/Program Files/ThisOtherProgram/Data.mdb" & _
            "Jet OLEDB:System database=;Jet OLEDB:Global Bulk Transactions=1;Jet OL" & _

    Changed to....

            Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Registry Path=;Data Source=""(Path)" & _
            "Jet OLEDB:System database=;Jet OLEDB:Global Bulk Transactions=1;Jet OL" & _

    Doesn't work...I did "Private path as String" but it doesn't like the (path) arguement in the statement

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 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

    17 Experts available now in Live!

    Get 1:1 Help Now