refering to a form's variables on a report

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I am using Access 97, and am a newbie as well.

I have created a form which has code that opens three
tables in sequence. I am pulling values out of a record
in each table, and am setting variables equal to the
values in the fields in those records. I eventually want
to have a report that displays the values of those
variables.

If I have a control on the form, say, a text box, set to
the value of one of the variables, then I can refer to
that text box in the report, and display the value of the
text box, and the underlying variable. Is it possible
for the form to refer directly to the variable, without a
corresponding linked text box, or other control? I have
spent a lot of time messing around with this, without
much luck.

Thanks in advance.
 
Steve said:
I am using Access 97, and am a newbie as well.

I have created a form which has code that opens three
tables in sequence. I am pulling values out of a record
in each table, and am setting variables equal to the
values in the fields in those records. I eventually want
to have a report that displays the values of those
variables.

If I have a control on the form, say, a text box, set to
the value of one of the variables, then I can refer to
that text box in the report, and display the value of the
text box, and the underlying variable. Is it possible
for the form to refer directly to the variable, without a
corresponding linked text box, or other control? I have
spent a lot of time messing around with this, without
much luck.

Thanks in advance.

Steve,
You can find the value of any record field in any table using DLookUp
without having the form bound to that table.
You can even use it directly in the report, so there may be no advantage
to having it in the form.

In an unbound control:
=DLookp("[FieldName]","TableName","[SomeCriteriaField] = " &
[SomeField])

The criteria above assumes [SomeField] is a number datatype.

Look it up in Access help.
Also look up
Where clause + How to restrict data to a subset of records
for way to write a where clause for other datatypes.
 
Thanks for the reply, Fred!

I am still vexed by this one, I guess.

Is it possible for a report to refer to a variable that
is not bound to any control on a form, nor to a field in
a table? An example would be, say, a variable of type
Long or Double that stores the result of a calculation.
If such a variable is not bound to a field or control,
can a report display the variable's value?

Thanks again in advance,
Steve

-----Original Message-----
Steve said:
I am using Access 97, and am a newbie as well.

I have created a form which has code that opens three
tables in sequence. I am pulling values out of a record
in each table, and am setting variables equal to the
values in the fields in those records. I eventually want
to have a report that displays the values of those
variables.

If I have a control on the form, say, a text box, set to
the value of one of the variables, then I can refer to
that text box in the report, and display the value of the
text box, and the underlying variable. Is it possible
for the form to refer directly to the variable, without a
corresponding linked text box, or other control? I have
spent a lot of time messing around with this, without
much luck.

Thanks in advance.

Steve,
You can find the value of any record field in any table using DLookUp
without having the form bound to that table.
You can even use it directly in the report, so there may be no advantage
to having it in the form.

In an unbound control:
=DLookp("[FieldName]","TableName","[SomeCriteriaField] = " &
[SomeField])

The criteria above assumes [SomeField] is a number datatype.

Look it up in Access help.
Also look up
Where clause + How to restrict data to a subset of records
for way to write a where clause for other datatypes.
--
Fred
Please reply only to this newsgroup.
I do not respond to personal e-mail.
.
 
Thanks for the reply, Fred!

I am still vexed by this one, I guess.

Is it possible for a report to refer to a variable that
is not bound to any control on a form, nor to a field in
a table? An example would be, say, a variable of type
Long or Double that stores the result of a calculation.
If such a variable is not bound to a field or control,
can a report display the variable's value?

Thanks again in advance,
Steve
If the variable is the result of a calculation in an unbound form
control and you wish to use it in a control in the report, you simply
refer to it in the report using:
=forms!NameOfForm!NameOfControl

If this is to be done using VBA, then you would use:
Dim SomeValue as Double
SomeValue = forms!NameOfForm!NameOfControl

The form must be open when the report is run.

If the variable is in a report event, and you wish to display the result
in a control in the report:

Add an unbound control to the report.
then code the event:
Dim SomeValue as Double
SomeValue = [FieldA] * [FieldB]
[ControlName] = SomeValue
 
Back
Top