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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resetting values to zero

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hi, everyone.
This shouldn't be too hard.
I have a table with many, many columns. The columns are variable though. They could change at any time. I want to write a query that will go in to this table and reset all of the values to zero (prepping for new months data entry). I have one column that is text that holds the dept name and it shouldn't change.

something like this psuedo code

for i = 2 to fieldCount <---field 1 should be fixed
update table set f(i) = 0 <--how do I get the column name
next i

this methodology isn't important either, it's just what occured to me at first. Alternate methods would be greatly appreciated.
Thanks
PB
 
Another way would be to create a table based on your current table (design only) and then insert the value in the text field(dept name), all numerical fields whould then be based on the default which you could set to 0

HTH

Andy
 
Hi PB,

Easy:

Code:
Dim fld As Field
Dim tdf As Table
Dim i as Integer

DoCmd.SetWarnings False ' otherwise you will get lots of &quot;Update confirm&quot; messages
Set tdf = CurrentDb.Tables (&quot;Tablename&quot;)

For i = 1 To (tdf.Fields.Count-1) ' indexes start from 0
	DoCmd.RunSQL &quot;Update table Set &quot; & tdf.Fields(i).Name & &quot; = 0&quot; ' replace with name of table
Next

DoCmd.SetWarnings True

You will need to add a reference to the Data Access Objects library 3.60 if you are using Access 2002 (should be fine with 97 or 2000).

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top