Passing variables between forms?

  • Thread starter Thread starter Tails
  • Start date Start date
T

Tails

I'm new-ish to access and I am trying to take input on one form, and pass it
to another.

I tried to declare a Public variable in general declaractions but it doesn't
seem to be working - the variable is always empty when the second form
loads?

Is there another way please?

Thanks.
 
You don't give us much details, but a public variable can be seen from
another form if you've declared it as public.

Another way to do this would be to write the value of the variable into the
OpenArgs argument of the OpenForm command, and then read that value in the
second form's OpenArgs property.
 
I do this by "hiding" the first form instead of closing
it -- until I am finished with the data.

For example:

frmDate has a date value in a textbox called txtDate that
you need on frmInvoice. When you open frmInvoice, hide
frmDate with the following code in the Load Event of
frmInvoice

Form Load

Forms!frmDate.Visible = False

This leaves the form open and you can "call" the Date with
the following code in whatever event you need. For
example, if there is a textbox on frmInvoice called
txtInvoiceDate you could do the following when the frm
loads:

Form Load

Me.txtInvoiceDate = Forms!frmDate.textDate

When you are finished using the data from the first form
(frmDate) you can close it or make it visible again from
within the second form (frmInvoice).

Let me know if this helps

Randy
 
Ken Snell said:
You don't give us much details, but a public variable can be seen from
another form if you've declared it as public.

Another way to do this would be to write the value of the variable into the
OpenArgs argument of the OpenForm command, and then read that value in the
second form's OpenArgs property.

--

Ken Snell
<MS ACCESS MVP>

pass

Thanks for taking the time to reply Ken.

I am experiencing a lot of wierdness at the moment - public variables don't
seem to be public, and if I ever use the date() or now() functions I get a
'library not found' error.

I'm guessing my office has a dodgy install of access, unless you have any
ideas for that please?

Thanks again.
 
Tails said:
I am experiencing a lot of wierdness at the moment - public variables don't
seem to be public, and if I ever use the date() or now() functions I get a
'library not found' error.

I'm guessing my office has a dodgy install of access, unless you have any
ideas for that please?


Try checking your References.

Open any code module (or open the Debug Window, using Ctrl-G, provided you
haven't selected the "keep debug window on top" option). Select Tools |
References from the menu bar. Examine all of the selected references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile All Modules), go back in
and reselect them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)

For far more than you could ever want to know about this problem, check out
http://members.rogers.com/douglas.j.steele/AccessReferenceErrors.html
 
Back
Top