Solved

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

Posted on 2001-08-30
3
955 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
[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 Comments
 
LVL 6

Expert Comment

by:xSinbad
ID: 6443372
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
ID: 6443480
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
ID: 6445708
Ok, that was easy! Thanks!! :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 56
vb6 connector to SQL Server 2 42
How does CurrentUser work? 10 42
Help me. 3 70
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

726 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