Can't Open DB File


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Can't Open DB File

  1. #1
    Join Date
    Sep 2004
    Posts
    45

    Can't Open DB File

    This snippet is supposed to open a db file for input. No matter how I write the file path I get an error message: “File Not Found.”
    The file path is C:\VisualBasic\ConnectToDB\MyDatabase.mdb.
    I use VB6, XP.

    The Turorial:
    'Connect a database to a form

    Dim dbMyDB As Database
    Dim rsMyRS As Recordset
    Private Sub form_load()

    'Attempts to open the DB

    ' First attempt, Set dbMyDB = OpenDatabase("MyDatabase.mdb")

    ' Second attempt, Set dbMyDB = OpenDatabase("C:\VisualBasic\ConnectToDB\MyDatabase.mdb")

    ‘Third attempt, Open App.Path & "MyDatabase.mdb" For Input As #1

    Set rsMyRS = dbMyDB.OpenRecordset("MyTable", dbOpenDynaset)
    If Not rsMyRS.EOF Then rsMyRS.MoveFirst

    Do While Not rsMyRS.EOF
    lstRecords.AddItem rsMyRS!Name
    lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
    rsMyRS.MoveNext
    Loop
    End Sub

    Private Sub lstRecords_Click()
    rsMyRS.FindFirst "ID=" & Str(lstRecords.ItemData(lstRecords.ListIndex))
    txtPhone.Text = rsMyRS!Phone
    End Sub

    Any advice will be greatly appreciated.

  2. #2
    Join Date
    Sep 2004
    Posts
    45
    Got it! I resolved this through the use of sheer pig headed tenacity.

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What did you do?

    If you solve your own problem, you should always post the solution you arrived at. It could help someone else, down the road, with the same or similiar problem.

    (As an aside: Why are you using DAO, which is very old and outdated, rather than ADO?)
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Sep 2004
    Posts
    45

    Open DB file Resolution

    This works
    Code:
    Private Sub form_load()
    Dim sPath As String
    
    Open "MyDatabase.mdb" For Input As #1
    
    Set dbMyDB = OpenDatabase("MyDatabase.mdb")
    Set rsMyRS = dbMyDB.OpenRecordset("MyTable", dbOpenDynaset)
    
    If Not rsMyRS.EOF Then rsMyRS.MoveFirst
    Do While Not rsMyRS.EOF
        lstRecords.AddItem rsMyRS!Name
        lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
        rsMyRS.MoveNext
    Loop
    
    End Sub
    
    Private Sub lstRecords_Click()
    
    rsMyRS.FindFirst "ID=" & Str(lstRecords.ItemData(lstRecords.ListIndex))
    txtPhone.Text = rsMyRS!Phone
    txtName.Text = rsMyRS!Name
    txtMoCost.Text = rsMyRS!MoCost
    txtKwh.Text = rsMyRS!kWh
    
    End Sub
    Last edited by Hack; 10-04-2010 at 07:53 AM. Reason: Added Code Tags

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Thank you for posting your resolution.

    (As an aside, I edited your post and added [code]your code goes here[/code] tags as it makes reading posted code a lot easier.)

    Thanks again.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Using Excel with VB.net
    By partyk1d24 in forum .NET
    Replies: 26
    Last Post: 03-28-2014, 02:49 AM
  2. I ask library open file access 2000
    By dong in forum VB Classic
    Replies: 9
    Last Post: 12-03-2009, 12:58 PM
  3. Replies: 1
    Last Post: 04-17-2006, 02:20 AM
  4. How to open a bmp file?
    By FrankWu in forum Java
    Replies: 0
    Last Post: 08-16-2002, 05:21 PM
  5. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 11:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center