Hi all,
I am trying with little success to update the fields of a table on a record that already exists. However, after running the code from a command button on the form the record's fields are still blank. Reason why I am doing it this way is because once the user has completed entering data for a few fields the rest of the fields can be automatically imported from a query at the press of a button. Around ten fields are populated this way but I have cut the code down to two as an example of how I have coded this:-
Dim db As Database
Dim rs As DAO.Recordset
Dim curTest01 As Currency
Dim curTest02 As Currency
Set db = CurrentDb
Set rs = db.OpenRecordset("tblCosts")
curTest01 = DLookup("[FieldValue01]", "qryQuery", "[FieldValue01]<> Null")
curTest02 = DLookup("[FieldValue02]", "qryQuery", "[FieldValue02]<> Null")
'These fields are created from the results of the fields above
With rs
.Edit
!tblField01 = curTest01
!tblField02 = curTest02
.Update
.Bookmark = .LastModified
.Close
End With
db.Close
Me.Refresh
Can anyone see why this will not populate the table ? If I use this code with .addnew the data populates but I want it to add to the already exisiting record, not to create a new record.
I tried using DoCmd.RunCommand acCmdSaveRecord at the end of the code but got error "runtime error 2046 the command or action 'saverecord' isn't available now" but I should not have to save the record manually anyway.
Any ideas why this code will not populate the record ?
Thanks in advance,
Mitch...
I am trying with little success to update the fields of a table on a record that already exists. However, after running the code from a command button on the form the record's fields are still blank. Reason why I am doing it this way is because once the user has completed entering data for a few fields the rest of the fields can be automatically imported from a query at the press of a button. Around ten fields are populated this way but I have cut the code down to two as an example of how I have coded this:-
Dim db As Database
Dim rs As DAO.Recordset
Dim curTest01 As Currency
Dim curTest02 As Currency
Set db = CurrentDb
Set rs = db.OpenRecordset("tblCosts")
curTest01 = DLookup("[FieldValue01]", "qryQuery", "[FieldValue01]<> Null")
curTest02 = DLookup("[FieldValue02]", "qryQuery", "[FieldValue02]<> Null")
'These fields are created from the results of the fields above
With rs
.Edit
!tblField01 = curTest01
!tblField02 = curTest02
.Update
.Bookmark = .LastModified
.Close
End With
db.Close
Me.Refresh
Can anyone see why this will not populate the table ? If I use this code with .addnew the data populates but I want it to add to the already exisiting record, not to create a new record.
I tried using DoCmd.RunCommand acCmdSaveRecord at the end of the code but got error "runtime error 2046 the command or action 'saverecord' isn't available now" but I should not have to save the record manually anyway.
Any ideas why this code will not populate the record ?
Thanks in advance,
Mitch...