Update records in a table

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Nicolae, Do you really need Field 3? How about if you add
Field 2 and Field 3 together in a query and have it report
out in a form or report? Food for thought. If you didn't
want that, you would need an update query that populates
Field 3 with the sum of Field 1 and Field 2. Then on
the "On Open" event, run a macro that runs that query.
Good Luck. Mike
 
Hi Mike,

Thank you for your reply.
You are right, it would be better that way. But I didn't make the
application myself and I don't want to rebuild everything there. There are
many forms and reports which pick up the data from that table (Field3) and I
would have to modify each of them to look in the query instead of the table.
Besides, my application doesn't actually need Field1 + Field2, but a
different function
I might do that, if it will prove easy enough for me (I am a beginner and I
don't know how to create a macro to do the sum of field1 + field2, I
simplified the function to be easier for people who help me).
At present I am looking for a quick fix. There are only a few hundred
records, and it really doesn't matter this solution is not the best one, as
long as it works correctly. I already found out what to do what I was
looking for and I replied to my message


Regards,
Nicolae




Mike said:
Nicolae, Do you really need Field 3? How about if you add
Field 2 and Field 3 together in a query and have it report
out in a form or report? Food for thought. If you didn't
want that, you would need an update query that populates
Field 3 with the sum of Field 1 and Field 2. Then on
the "On Open" event, run a macro that runs that query.
Good Luck. Mike
-----Original Message-----
Hi All,

I have a database with a table and a form.The fields of the table are

ID Field1 Field2 Field3

I want to create a function so when I open the form to have all the records
from Field3 updates as sum of Field1 + Field2
I asociated a function to the Open Form event and trying to figure out what
code to use


************************************************

Private Function UpdateDepreciation()
Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Dim intOption As Integer


Set dbs = CurrentDb()
strSQL = "SELECT * FROM tbAssets"
strSQL = strSQL & " ORDER BY [ID];"
Set rst = dbs.OpenRecordset(strSQL)

While (Not (rst.EOF))
???
Wend

rst.Close
dbs.Close

End Function

************************************************


Any help would be appreciated

Regards,
Nicolae


.
 
Back
Top