Solved

Using ADO to open a DBF file

Posted on 2000-04-03
6
407 Views
Last Modified: 2008-03-06
I'm having difficulty opening a dBASE data file using ADO.  I need to be able to append records to this file from my VB 6 app.  I tried the following code which was based on information I got from the Microsoft web site:

dim con As New ADODB.Connection
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\rssc\Emcr.dbf; Extended Properties=dBASE III;"

The error message I get is ...

'c:\rssc\Emcr.dbf' is not a valid path.  Make sure that the path name ...(blah, blah, blah)...

I've verified that this is the correct path to the filename and this file is a valid dBASE file (I imported it successfully into an Access table).  I don't know for sure whether this DBF file came from dBASE III, IV, V or perhaps FoxPro (how can I tell?)  Also, how can I tell if my OLEDB provider version info is correct?  Any help will be greatly appreciated.
0
Comment
Question by:rmayer
  • 3
  • 2
6 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 2680674
Since dBase files are not a real database, the "Data Source" property of your connection must be set to the folder name containing your DBFs files. This folder act as a database.

dim con As New ADODB.Connection
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\rssc\; Extended Properties=dBASE III;"

The Recordset object will contain the name of your file (which is consider to be a table in a database).
0
 

Author Comment

by:rmayer
ID: 2681257
Thanks for the information.  Although I can now open the database and read through the records, I am still unable to add records to it.  The message I get indicates that the provider does not support this operation.  Is there any known way to do this?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2681330
Why a "C"?

Here is probably why you can't (check carefully for the CursorType property):

Private Sub Command1_Click()
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset

    con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\apps\office\; Extended Properties=dBASE III;"
    With rst
        Set .ActiveConnection = con
        .LockType = adLockOptimistic
        .CursorType = adOpenStatic
        .CursorLocation = adUseClient
        .Source = "Clients"
        .Open
       
        .AddNew
        .Fields(0).Value = "MOREAU3"
        .Update
       
        .MoveFirst
        Do Until .EOF
            Debug.Print .Fields(0).Value
            .MoveNext
        Loop
       
    End With
End Sub
0
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

 

Author Comment

by:rmayer
ID: 2681413
Thanks again for the clarification. The "C" grade was based on the fact that your original answer didn't solve my real problem and that was to be able to append records to the DBF file.  However, your subsequent comment spelled it out clearly (I had forgotten to change the recordset's read-only properties).  Anyway, I will gladly regrade you to "A", but I'm not sure if/how this can be done.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2681448
You can ask administrators to correct this, or you can post a new question titled something like: "for emoreau"
0
 
LVL 3

Expert Comment

by:darinw
ID: 2685605
emoreau, please see your question:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10322921

darinw
Customer Service
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

12 Experts available now in Live!

Get 1:1 Help Now