DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: VB6 Won't Open Access DB

  1. #1
    Join Date
    Sep 2004
    Posts
    45

    VB6 Won't Open Access DB

    Worked with a tutorial that is supposed to open a db file for input. No matter how I write the file path I get error messages .
    The first attempt to open the file path that came with the tutorial generated the error message “Couldn’t find file.”
    The next two attempts are my doctoring. Attempt #2 generated error message “Unrecognized DB format.” Third attempt error message is, “File Not Found.” I use VB6, XP.

    'Connect a database to a form
    Dim dbMyDB As Database
    Dim rsMyRS As Recordset

    Private Sub form_load()

    'Open DB Attempts
    ' 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

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Second attempt is correct. Here's how to fix the "unrecognized database format" error: http://support.microsoft.com/kb/238401
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Sep 2004
    Posts
    45

    VB6 Won't Open Access DB

    Thanks for responding so quickly Phil. Curious how I could set the path if I decide to share this with some colleagues no matter what folder they save it in. I thought App.Path was the way to go.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    The problem with App.Path is that non-administrators don't have write access to C:\Program Files. You should probably install the database to the user's AppData\Local folder and use the SHGetSpecialFolderLocation function to find it: http://hashvb.earlsoft.co.uk/Special_folders
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Sep 2004
    Posts
    45
    Interesting. A couple of years ago I wrote a small program that returns town names and zip codes when the user enters a telephone exchange. (The DB is a text file.) I used App.Path, shipped it to them and it works fine for them. Is that because I used a text file instead of access?

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    No, it's probably because they're running as an Administrator on their PC. Unlike previous versions of Windows, Vista and Windows 7 do not make users Administrators by default.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Sep 2004
    Posts
    45

    VB6 Won't Open Access DB

    I see. The folks I sent the program to use XP and are likely designated administrators. Thanks Phil.

Similar Threads

  1. VB6 Connect to remote Access DB on server
    By vbxmax in forum VB Classic
    Replies: 2
    Last Post: 11-23-2005, 02:21 AM
  2. Replies: 0
    Last Post: 01-31-2002, 09:15 PM
  3. Is access already open
    By Gregoire in forum VB Classic
    Replies: 0
    Last Post: 12-11-2001, 07:27 AM
  4. Access & SQL Server
    By David Jones in forum Database
    Replies: 0
    Last Post: 08-31-2001, 12:22 PM
  5. setting up multiuser env. using vb6 (DAO) & Access 97
    By Jonathan Sullivan in forum VB Classic
    Replies: 0
    Last Post: 04-12-2001, 05:39 AM

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