variable values: gone?

  • Thread starter Thread starter Fredrated
  • Start date Start date
F

Fredrated

I have a subform that declares some string form variables Private and loads
them in the form.open event, as in:
Private AgendaDIR As String
(I have also used DIM AgendaDIR As String with the same effect)

at form.open I load the variables (dg is an object that fetches values on
request):
dg.LoadDirectories

UploadDIR = dg.UploadDirectory
AgendaDIR = dg.AgendaDirectory
MinutesDIR = dg.MinutesDirectory
AttachDIR = dg.AttachDirectory

At this point debug reports that the directory values have been retrieved
correctly.

Then when I want to use them in a routine they have been reset to blank.
This happens even if I request a value as the first thing I do after the form
opens.

Any idea what happened to the values and how to stop loosing them?

Thanks in advance for any help.

Fred
 
What version of Access is this? 2007?

Trying to work with variables like that tends to get frustrating. There are
cases where Access reloads the form (changing SourceObject is an obvious
example, but changing the main form's or subform's RecordSource might do
it), and they are also lost when you reset the project. It would be much
safer to use hidden controls to hold the variables.

Access 2007 also has TempVars that don't get reset. But they are global, so
there's a much higher chance of them being interferred with by other
processes, and they are not specific to the instance of the form (e.g. where
you reuse subforms.)
 
It would be much safer to use hidden controls to hold the variables.

Thanks, that worked perfectly. I've had other instances where variable
values disappeared, I can see that this will be a technique I will use a lot.

Fred
 
Fredrated said:
Thanks, that worked perfectly. I've had other instances where variable
values disappeared, I can see that this will be a technique I will use a
lot.

Fred
<SNIP>

If you have a few hidden controls on a form you sometimes find they 'get in
the way', or are distracting as you design the form. Here's a trick to
circumvent this. With the form open in design view, select View | Page
Header/Footer. Shrink the page header to nothing, then place your hidden
controls on the page footer. That way you can still easily access them in
design, but users will never see them on screen at runtime. And of course
they're out of your way while form designing.
 
Back
Top