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
Solved

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

Posted on 2001-08-30
3
952 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

829 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