Solved

Using ADO to open a DBF file

Posted on 2000-04-03
6
415 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 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

696 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