?
Solved

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

Posted on 2001-08-30
3
Medium Priority
?
970 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 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

762 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