Log in

View Full Version : how do I use variable with addNew



amfivian
12-06-2007, 01:44 PM
Hi. I'm new at this :banghead:. Can any please tell me how i can modify the following code to use a variable in place 'name' with addNew.
Thanks in anticipation. Andrew

Public Sub addNewRecord(newData As String, myTable As String)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim obj As Object
Set db = CurrentDb()
Set rst = db.OpenRecordset(myTable, dbOpenDynaset)
With rst
.addNew
'!name = newData
.Update
.Bookmark = .LastModified
End With
rst.Close
End Sub

DarkSprout
12-11-2007, 06:49 AM
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset(myTable, , dbAppendOnly)
With rst
.AddNew
![FieldName] = newData
.Update
.Bookmark = .LastModified
End With
rst.Close