Solved

How to add new record to dbf file in VB using DAO?

Posted on 2001-08-30
3
929 Views
Last Modified: 2006-11-17
Hi

Can anyone tell me how to add new records to a dbf table (file) in VB code using DAO for connectivity? I attempted the following but got an error message saying recordset is read-only and not updatable:

    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Set db = OpenDatabase(theDBFFilePath, True, True, "dBase 5.0;")
    Set rs = db.OpenRecordset("dbfName", dbOpenTable, dbAppendOnly)
    rs.AddNew
        rs.Fields(0).Value = "test"
        rs.Fields(1).Value = 10
    rs.Update


Thanks!

0
Comment
Question by:ahpui
3 Comments
 
LVL 6

Expert Comment

by:xSinbad
Comment Utility
Have you tried 'dbOpenDynaset'

Set rs = db.OpenRecordset("dbfName", dbOpenDynaset, dbAppendOnly)

I have never use DAO on a DBF file but the code looks OK, could there be something wrong with the file?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 50 total points
Comment Utility
Here is the definition of the OpenDatabase Method:

Set database = workspace.OpenDatabase (dbname, options, read-only, connect)

So I suspect this line:
Set db = OpenDatabase(theDBFFilePath, True, True, "dBase 5.0;")

Ought to read:
Set db = OpenDatabase(theDBFFilePath, True, False, "dBase 5.0;")

Anthony
0
 

Author Comment

by:ahpui
Comment Utility
Ok, that was easy! Thanks!! :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now