You need to open the recordset with a dynamic cursor if you want to write back to the DB. In both these cases you are using a Static cursor.
If you change adOpenStatic to adOpenDynamic in the second procedure, you should be able to write to the table. You also don't need the IF statement.
VB Code:
Private Sub test() Dim rst As ADODB.Recordset Set rst = New ADODB.Recordset rst.Open "Table1", CurrentProject.Connection, adOpenDynamic, adLockOptimistic rst.AddNew rst.Fields("test") = "txt1" rst.Update rst.Close Set rst = Nothing End Sub




Reply With Quote