Solved

Using ADO to open a DBF file

Posted on 2000-04-03
6
408 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

863 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

20 Experts available now in Live!

Get 1:1 Help Now