Referencing a variable accross forms.

  • Thread starter Thread starter Brendan
  • Start date Start date
B

Brendan

This should be an easy thing to do but it is giving me a huge
headache.

I have a switchboard form (called Report) and a form it opens is
called frm_Chapter. This is not a subform, but contains two listboxes
used for filtering a query. I have saved the information in a variable
called StrValue. When the user clicks OK on the frm_Chapter form, the
form is hidden so that the variable can be referenced. When the
report form executes a report, all forms are then unloaded / closed.

Right now I am just trying to reference the StrValue from frm_Chapter
to the Report form. For simplicity sake I am doing this with a
message box. However I continue to get a 2465 error claiming it cant
find the field on the form.

Msg = Form_frm_Chapter!StrValue

This is the syntax I am using currently trying to read in the value
that will be used in a message box. Does anyone have any ideas?
Thanks

Brendan
 
If strValue is a variable in an event procedure for your
frm_Chapter form, it vanishes as soon as the procedure
ends. There is no way to refer to it.

If you wish to use this value, you could define strValue
as a Public variable in a global code module, so that it
remains in scope for use by other forms, or you can store
the value in a non-visible control on your form. To do
the latter, add a textbox control anywhere on your form,
and set its Visible property to No.

Then store your query string there:

Me!yourhiddentextboxname = strValue

To refer to this value from another form, the syntax is:

Forms!frm_Chapter!yourhiddentextboxname

HTH
Kevin Sprinkel

Msg = Forms!frm_Chapter!StrValue
 
Although the variable may have been declared within a form module, it does
not belong to the form so FormName!Control doesn't work. If you do not
store the value of the variable into a text box just refer to the variable
directly.

Msg = StrValue

Kelvin
 
Back
Top