R
RockNRoll
I was having a problem with the ADO AddNew method not adding my new records,
so I created a simple sub with miscellaneous values to troubleshoot it.
The problem is that everything goes fine and my MsgBox test at the end even
works, but when I go back to my Access tables, the record has not been added
at all.
The table is currently empty and has an autonumber primary key (not in the
code - I'm assuming Access will assign it a value when it creates the
record). Could that be why the record is not being added?
I would really appreciate anyone's input on this one. Please tell me what
I'm doing wrong.
Anyway, here is my code:
Sub TestAddReimbursement()
Dim Reimbursement_tbl As New ADODB.Recordset
Reimbursement_tbl.Open "tbl_Reimbursement", CurrentProject.Connection,
adOpenStatic, adLockOptimistic
If Reimbursement_tbl.Supports(adAddNew) Then
Reimbursement_tbl.AddNew
Reimbursement_tbl.Fields("Reimbursement Amount") = 235
Reimbursement_tbl.Fields("Reimbursement Date") = Date
Reimbursement_tbl.Fields("Expense Receipt Number") = 12
Reimbursement_tbl.Update
MsgBox (Reimbursement_tbl![Reimbursement Amount])
End If
End Sub
so I created a simple sub with miscellaneous values to troubleshoot it.
The problem is that everything goes fine and my MsgBox test at the end even
works, but when I go back to my Access tables, the record has not been added
at all.
The table is currently empty and has an autonumber primary key (not in the
code - I'm assuming Access will assign it a value when it creates the
record). Could that be why the record is not being added?
I would really appreciate anyone's input on this one. Please tell me what
I'm doing wrong.
Anyway, here is my code:
Sub TestAddReimbursement()
Dim Reimbursement_tbl As New ADODB.Recordset
Reimbursement_tbl.Open "tbl_Reimbursement", CurrentProject.Connection,
adOpenStatic, adLockOptimistic
If Reimbursement_tbl.Supports(adAddNew) Then
Reimbursement_tbl.AddNew
Reimbursement_tbl.Fields("Reimbursement Amount") = 235
Reimbursement_tbl.Fields("Reimbursement Date") = Date
Reimbursement_tbl.Fields("Expense Receipt Number") = 12
Reimbursement_tbl.Update
MsgBox (Reimbursement_tbl![Reimbursement Amount])
End If
End Sub