Solved

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

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

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now