This example prompts the user to select a cell that contains a value for the COMPANY field of the Customer recordset in the Nwindex.mdb database. The example then checks to see whether the recordset can be updated. If so, the example adds a new record to the recordset, using the value in the selected cell.
To create the Nwindex.mdb database, run the Microsoft Excel example for the CreateDatabase method.
Dim db As Database, rs As Recordset
Sheets("Sheet1").Activate
cellToCopy = Application.InputBox("What cell value do you want" _
& " to update as company?", Type:=8)
If cellToCopy = False Then ' user cancelled InputBox
Exit Sub
End If
Set db = Workspaces(0).OpenDatabase(Application _
.DefaultFilePath & "\NWINDEX.MDB")
Set rs = db.OpenRecordset("Customer")
With rs
If .Updatable = True Then
.AddNew
rs("COMPANY") = cellToCopy
.Update
.MoveLast
MsgBox "The new company is " & rs("COMPANY").Value
Else
MsgBox "The recordset cannot be modified."
End If
End With
rs.Close
db.Close