sql - Access Loop Thru Columns to update records -
i have access table 20 columns, each column unique name, columns want update start tt. columns have 1 word in them "applied", not records populated. want run summary reports on data, want change word "applied" number "1". problem column names change, new column added or removed @ time, don't want hard code column names in sql statement.
what best way cycle thru of columns , update records in each column without defining each column static name? need keep original record "applied", able use number 1 in it's place needed.
there 6mil records in table.
you can't updated fields or (columns), can update records (or rows). however, can figure out fields fit description. don't understand question, maybe can add field names array, strip array out , update fields start "tt". code find field names follows:
function tableinfo(strtablename string) on error goto tableinfoerr ' purpose: display field names, types, sizes , descriptions table. ' argument: name of table in current database. dim db dao.database dim tdf dao.tabledef dim fld dao.field dim strsql string set db = currentdb() set tdf = db.tabledefs(strtablename) each fld in tdf.fields if left(fld.name, 2) = "tt" 'your field name starts tt. processing... strsql = "update " & strtablename & " set " & fld.name & " = 1 " & fld.name & " = 'applied'" docmd.execute strsql end if next tableinfoexit: set db = nothing exit function tableinfoerr: select case err case 3265& 'table name invalid msgbox strtablename & " table doesn't exist" case else debug.print "tableinfo() error " & err & ": " & error end select resume tableinfoexit end function
Comments
Post a Comment