?
Solved

Using ADO to open a DBF file

Posted on 2000-04-03
6
Medium Priority
?
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 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 70

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 70

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

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