vba - Public variable goes out of scope -
my public variables losing scope when execution moves sub in different module. can't fathom why happening.
module a:
option compare database public db dao.database public xlapp excel.application sub main() dim db dao.database set db = currentdb processfiles ' upload data report files appendtopentana ' transfer data main tables pentana export table producefinalexport ' export final data excel end sub
module b:
sub processfiles() dim recset recordset ' open recordset containing keywords in file names identify area set recset = db.openrecordset("tblfiles") ' rest of code end sub
in module b variable db has been set nothing , object ref error. i've tried using older 'global' declaration rather public same result.
public variables commonly used, don't what's going wrong here.
sub main() dim db dao.database set db = currentdb
you have additional local variable db
in main
, , 1 set. local variables have precedence on global ones.
just remove dim
line main
, work.
wiki
Comments
Post a Comment