Run SQL query for each field in table

elektr

Registered User.
Local time
Yesterday, 19:25
Joined
Apr 20, 2009
Messages
22
Hi!
Could anyone help me with this:
I have a table with 50 fields (all text) and I would like to run an update query on all of these, here's an example:
Code:
UPDATE Sheet1 SET Sheet1.[28] = 0
WHERE (((Sheet1.[28])=""));

The fields are numbered 1-50

I appreciate any help
Thanks
 
Code:
Dim nIndex As Integer
Dim strSql As String

DoCmd.SetWarnings False
For nIndex = 0 To 49

   strSql = "UPDATE TableName SET Field" & Cstr(nIndex+1) & " = 0 WHERE Field  & Cstr(nIndex+1) & " = '';"

   DoCmd.RunSQL strSQL
   Debug.Print "Field " & nIndex+1
Next nIndex
DoCmd.SetWarings True


Drop this code in a module as a function and run the function from the immediate window.
 
Thanks a lot!
 

Users who are viewing this thread

Back
Top Bottom