Solved

Using ADO to open a DBF file

Posted on 2000-04-03
6
412 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
how can i unlock a picture file that was loaded in a picturebox in visual c#? 4 125
Help me. 3 77
MsgBox 4 75
Fastest way to find and count same items VB6 16 62
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

739 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