Add Records in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
You can use SQL:

CurrentDb.Execute "INSERT INTO MyTable (Field1, Field2) VALUES (5, 'abc'),
dbFailOnError

or you can open a recordset and use its AddNew method:

Dim rsCurr As DAO.Recordset

Set rsCurr = CurrentDb.OpenRecordset("SELECT Field1, Field2 FROM MyTable")
With rsCurr
.AddNew
!Field1 = 5
!Field2 = 'abc'
.Update
End With
rsCurr.Close
Set rsCurr = Nothing
 
How can i use the following method in INSERT INTO?

INSERT INTO ..... VALUES('01.01' & Year(Date))

I want to add a static(Day & Month) & dynamic(Year) value at the same time.
But how?
 
How can i use the following method in INSERT INTO?

INSERT INTO ..... VALUES('01.01' & Year(Date))

I want to add a static(Day & Month) & dynamic(Year) value at the same time.
But how?

If it's a date field, insert a date value: a date *is not a string*!

Values(DateSerial(Year(Date()), 1, 1))

will do it for you.

John W. Vinson [MVP]
 
Back
Top