get the name of a query from an access table, then run the query -
i have access db pulls volumes table of exceptions. each volume has id. i've created queries pull details, possible volumes, , saved each 1 same name each volume id. each time volume exceptions pulled db, volume ids can change. so, there query runs updates volume table new ids.
unless know way query, need write access vba code loop through volume table, identify name of each query , run queries until reaches end of table. example, code needs @ first record in volume table, 1040. name of query needs run. code needs find query named 1040 , run it. make table query.
the table name facilityvolume , has 1 field named volume. value in field shorttext format though numeric.
i've tried couple of different things. here latest try.
dim db database dim vol recordset dim code querydef set db = currentdb() set vol = db.openrecordset("facilityvolume") set volume = vol.fields("volume") vol.movefirst until vol.eof = true if querydef.name = volume docmd.openquery else msgbox("the query not exist") vol.movenext loop end sub
i've searched internet few days , can't find reference particular code. i'm sure other users know how this. i'm novice , still learning vba can provide appreciated.
your code loop through, if found query , not pass query-name openquery command... won't work...
the collection currentdb.querydefs
knows existing queries, there no "exists" or "contains" method.
so: approach loop (as tried it) or error handling.
it's quite time ago since i've coded vba, think try:
on error resume next docmd.openquery "yourqueryname" if err msgbox("the query not exist!") err.clear end if on error goto 0
Comments
Post a Comment