vba - Global variable loses its value -


on access form working on have global variable take value form on form_load event. reason unknown me variable "loses value" (becomes = "") after time elapses or event occurs. have not been able notice in particular triggers behaviour. global variables reset after time of "inactivity" on form ?

here how set global variables talking about:

private sub form_load()            '...     set prev_form = form_identification.form     passwordsybase = prev_form.password.value & vbnullstring     usersybase = prev_form.userid.value & vbnullstring     '... end sub 

an alternate solution (only 2007 , onwards) i've started using tempvars instead of globals in odd situation "needed" global. it's collection , persists duration of application unless explicitly release it. in cases feel more useful globals , in cases worse.

tempvars.add myvarname, myvarvalue ' initialize tempvars.item(myvarname) = newvarvalue ' reference , assign new value tempvars.remove(myvarname) ' release 

quick search should show more lot references, i've included link basic one

http://blogs.office.com/b/microsoft-access/archive/2010/09/27/power-tip-maximize-the-user-of-tempvars-in-access-2007-and-2010.aspx


Comments