Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Calculate a field in a table using other fields in same table 1

Status
Not open for further replies.

dbanker

Technical User
Sep 26, 2007
30
0
0
US
I have a table that has three fields in it. Two have data and one is empty. I want to write a procedure to calculate a value and enter it in the empty field using values located within the same record in the other two fields, and would like to do this for every record in the table. Does anyone have a suggestion? Thanks in advance.
 
I have done this before by making a module

typed not tested but you get the gist.

set db = currentdb

set rs=db.openrecordset(TABLENAME)

rs.movefirst
do while not rs.eof

rs.edit
rs("field2")=rs("field1")*rs("field2")
rs.update
rs.movenext
loop

set rs=nothing
set db = nothing

Then run module

you may get some error but you have a starting point and should be able to tweak it to work


ck1999
 
Why? Normally calculated values are not saved in the table, unless there are pending reasons to do so. Do your calculations on the form, report, or query.
 
Thanks I'm sure I can get that code to work. I just couldn't remember the "edit" and proper syntax for navigating through the records.

To answer you MajP, it is a long story but I'm using the data in that table in a Sequential Connect with ArcView GIS software and it needs to be saved in the table to do so.
 
Why not simply an UPDATE query ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Code:
UPDATE YourTableName SET Field3 = Field1 + Field2

Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top