How to control a report from a form?

  • Thread starter Thread starter GZ
  • Start date Start date
G

GZ

Hi, there:
I have created a form. On the form there are some text boxes. I want to add
a button to print the content of the form by print a report. I have no ideal
how to transfer data on the form to the report.

On the report, I wrote:

Dim StrStdId As String
StrStdId = Form_Invoice.txtStdID_Onform
txtStdID_OnReport = StrStdId

It seems the report can recognize the data in the form Invoice (strStdID
got a value from the form), but I cannot assign the data to
txtStdID_OnReport. It said: "You cannot assign a value to this object"

Anyone can help?

Thanks!

GZ
 
GZ said:
I have created a form. On the form there are some text boxes. I want to add
a button to print the content of the form by print a report. I have no ideal
how to transfer data on the form to the report.

On the report, I wrote:

Dim StrStdId As String
StrStdId = Form_Invoice.txtStdID_Onform
txtStdID_OnReport = StrStdId


When you use the button wizard to create a button that opens
the report, it generates some code that you can change
slightly to do what you want. Find that code and change it
to use this kind of logic:

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "nameofreport"
stLinkCriteria = "stdidfieldname = " & txtStdID
DoCmd.OpenReport stDocName, , , stLinkCriteria
 
Remember"

Your data is not in the form or the report. It is in the underlying table.
You can use the form to specify which records of the underlying table the
report will print. As marshall described\

Tom
\
 
Thanks for reply, However, both the form and report are not bound to any
table or query, so I got the error:

"The action or method is invalid because the form or report isn't bound to a
table or query."

I am just wondering, in such ciruistance, how can I transfer data from a
form to a report. I mean, on the form, there is a text box has value
"StdID_123", what I need is let the text box on the report has the same
value and print the report.

Is this possible?

Thanks!

GZ
 
GZ said:
Thanks for reply, However, both the form and report are not bound to any
table or query, so I got the error:

"The action or method is invalid because the form or report isn't bound to a
table or query."

I am just wondering, in such ciruistance, how can I transfer data from a
form to a report. I mean, on the form, there is a text box has value
"StdID_123", what I need is let the text box on the report has the same
value and print the report.

If neither are bound to a data table, how do you remember
what the data is from one time to another?? I don't
understand what you're doing.

Whatever. A text box on a report (or another form) can
refer to a value in a control on your form (as long as the
form remains open) by using a reference like:

=Forms!Invoice.txtStdID

without using any code. The same reference could be used in
code in the report (but not in the Open event) if you want:

Dim StrStdId As String
StrStdId = Forms!Invoice.txtStdID
Me.txtStdID = StrStdId
--
Marsh
MVP [MS Access]


 
Back
Top