Adding records with VBA

T

tina

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("TableName", dbOpenDynaset)

rst.AddNew
rst("TextFieldName") = "something"
rst("NumberFieldName") = 1
rst("Date/TimeFieldName") = #7/28/2007#
rst.Update

rst.Close
Set rst = Nothing

if you're new to Access (not just VBA in Access), suggest you consider
whether you need code to add a table record at all. if you can bind the
table to a form, and just enter the data directly to the table via the form,
that's quicker and easier.

hth
 
S

Syed Zeeshan Haider

Hello Everybody,
In Access 2003, is it possible to add new records in a table with VBA? If
yes then how?
I have been looking in VBA help but found no clue. I have some personal
experience in VB6 and VBA of Excel but none in VBA of Access.

Thank you,
 
D

Douglas J. Steele

Another approach, of course, is to use SQL through VBA:

Dim strSQL As String

strSQL = "INSERT INTO TableName " & _
"(TextFieldName, NumberFieldName, DateTimeFieldName) " & _
"VALUE ("something", 1, #7/28/2007#)"
CurrenDb.Execute strSQL, dbFailOnError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top