Access VBA: New tables created in a loop causing error -
i'm grabbing field row 1 table , creating new table each row. new tables have names equal row correspond to.
here code:
option compare database public function createtables() dim db dao.database dim tdf dao.tabledef dim rst dao.recordset dim fld dao.field dim strsql string strsql = "select skus skus" set db = currentdb() set rst = db.openrecordset(strsql) set fld = rst.fields("skus") 'msgbox fld.value rst.movefirst while not rst.eof set tdf = db.createtabledef(fld.value) set fld = tdf.createfield("skus", dbtext, 30) tdf.fields.append fld set fld = tdf.createfield("count", dbinteger) tdf.fields.append fld db.tabledefs.append tdf rst.movenext loop end function
the problem after first iteration of code (the first table created), gives me error "invalid operation" pointing line
... set tdf = db.createtabledef(fld.value) ...
why think is? have feeling because need re set fld or rst, i'm not sure.
can me out this? thanks!
it doesn't seem you're reading new tuples rst
, createtabledef
called same value repeatedly. try changing this:
[...] set fld = rst.fields("skus") rst.movefirst while not rst.eof set tdf = db.createtabledef(fld.value) [...]
into this:
[...] rst.movefirst while not rst.eof set fld = rst.fields("skus") set tdf = db.createtabledef(fld.value) [...]
...if intention create 1 table based on every tuple in skus table.
Comments
Post a Comment