i have an array and I will be filling the table with, each field independantly with a loop. This works fine. It keeps adding to the last row, and each field with no issue.
To avoid issues in future. Would this be ok, or should I make it more robust?
Issues im contemplating..
- I have read that you must move to last line before adding data, my sub works, is this necessary?
- is looping each field best way? or is there a way to enter array in 1 shot across fields that is better? thanks
To avoid issues in future. Would this be ok, or should I make it more robust?
Issues im contemplating..
- I have read that you must move to last line before adding data, my sub works, is this necessary?
- is looping each field best way? or is there a way to enter array in 1 shot across fields that is better? thanks
Code:
Sub test()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim x As Variant
Set db = CurrentDb
Set rs = db.OpenRecordset("test")
x = Array("Mike", "Sanchez, "Teacher")
With rs
.AddNew
For i = 0 To UBound(x)
rs.Fields(i + 1).Value = x(i)
Next
End With
rs.Update
rs.Close
DoCmd.OpenTable "test"
End Sub