473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

export variable from a form to a report using VBA

Hello all,
I m quite sure that s a common problem and even that the answer to it
has been given somewhere, forgive my lack of perspicacity but here is
my problem:

In the vba code of a button on a form, leading to the preview of a
report, I ve got a variable (string) which has been filled with some
information from a SQL querry. I want to export this variable to the
report to be previewed.
The report has been built before with the assistant and the button on
the form has a command looking like DoCmd.Open "form"....

What would be the best way then to add a textbox or a label on the
report with the string resulting from the SQL querry?

What I ve been trying to do so far is to add a textbox on the report
and add in vba code something like
Reports!Invoice_Report.TextBoxAdress= var, but even if the debugger
doesnt complain, the textbox is empty (even though I m sure I ve got
the good value in var).

Any hints or pointer to a web page would be appreciated.
Nov 12 '05 #1
3 2740
sc******@cf.ac.uk (Thierry Schmitt) wrote in message news:<42**************************@posting.google. com>...
Hello all,
I m quite sure that s a common problem and even that the answer to it
has been given somewhere, forgive my lack of perspicacity but here is
my problem:

In the vba code of a button on a form, leading to the preview of a
report, I ve got a variable (string) which has been filled with some
information from a SQL querry. I want to export this variable to the
report to be previewed.
The report has been built before with the assistant and the button on
the form has a command looking like DoCmd.Open "form"....

What would be the best way then to add a textbox or a label on the
report with the string resulting from the SQL querry?

What I ve been trying to do so far is to add a textbox on the report
and add in vba code something like
Reports!Invoice_Report.TextBoxAdress= var, but even if the debugger
doesnt complain, the textbox is empty (even though I m sure I ve got
the good value in var).

Any hints or pointer to a web page would be appreciated.


What if you create a wrapper function that assigns the resulting
variable to the function name, and then put that on your report?
Nov 12 '05 #2
Thierry,
This is how I got mine to work... although my function is really
simple and stupid, but there's no reason you can't show the result of
a function on a report.

Okay, my function:

Public Function MyVariable() As String
MyVariable = "Jimi Hendrix"

End Function

Yes, simple and stupid, I know...

On my report, I have a textbox with its control source set to:
=MyVariable()

And I get the value in the control source on my report. Or is your
value supposed to change for each record? If so, just put it in the
Detail section of your report, and pass a fieldname from your
rowsource to it.

e.g.
Public Function TypeBackwards(ByVal strValue As String) As String
TypeBackwards = StrReverse(strValue)
End Function

Text13.Rowsource==TypeBackwards([Service])
(where Service is a field on my report.)

HTH,
Pieter
Nov 12 '05 #3
If the tag property of the button is not being used, assign the variable to
it and have the textbox on the report reference the form control in it's
OnLoad event.

Example: In Button Code
Me!Button.Tag = Var

In Report OnOpen (Maybe OnLoad) Event
Me!TextFromButton = Forms!FormName!Button.Tag)

Of course the form will need to remain open until the report is finished
opening.

Mike Storr
www.veraccess.com
"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
sc******@cf.ac.uk (Thierry Schmitt) wrote in message

news:<42**************************@posting.google. com>...
Hello all,
I m quite sure that s a common problem and even that the answer to it
has been given somewhere, forgive my lack of perspicacity but here is
my problem:

In the vba code of a button on a form, leading to the preview of a
report, I ve got a variable (string) which has been filled with some
information from a SQL querry. I want to export this variable to the
report to be previewed.
The report has been built before with the assistant and the button on
the form has a command looking like DoCmd.Open "form"....

What would be the best way then to add a textbox or a label on the
report with the string resulting from the SQL querry?

What I ve been trying to do so far is to add a textbox on the report
and add in vba code something like
Reports!Invoice_Report.TextBoxAdress= var, but even if the debugger
doesnt complain, the textbox is empty (even though I m sure I ve got
the good value in var).

Any hints or pointer to a web page would be appreciated.


What if you create a wrapper function that assigns the resulting
variable to the function name, and then put that on your report?

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation....
2
by: Vikrant | last post by:
Hey Friends I need to export an Access Report using a filter. I am using the method OutputTo m_pDoCmd->OutputTo( 3, // asOutputReport COleVariant(strReportName), // <report name>...
1
by: Scott Sabo | last post by:
I have a form & report based on a query which shows details about employees performance reviews (hire date, review date, review submital date, etc). We do 90 day probation reviews as well and I...
2
by: Gt394 | last post by:
I have a form called frm_quote and a report called rpt_quote. I want to be able to view the form on a particular quote number (field: QuoteNo - autonumber) and then go to the report where the the...
0
by: Benny Ng | last post by:
Dear ALl, Now I want to export the crystal report to Excel file. But actually don't know how to export it with multiple sheet. Because sometime in some particular cases. It needs us to provided an...
4
by: lorirobn | last post by:
Hi, I have a main menu that opens several different reports. I am adding an OrderByOn, and currently have it set up for one report with the following statements: !.OrderBy = strOrderBy...
0
by: Michael Fay in SB | last post by:
I built my application with Access 2003 and made a distribution using the Microsoft Office Access 2003 Developer Extensions. (I also install Jet 8 as a follow-on action at the end of the...
1
by: Peter Herath | last post by:
I have created a report using sample codes taken by the forum. one problem is that the report displays the field/column names in the table in columnar format(field names display in rows.) but i want...
3
by: acextreme | last post by:
Hi all, I have a big problem when I try to export from Crystal Report 8.5 in .pdf from VB6. I use a database made in SQL Server 2000. The problem is that all the decimal fields in database are...
0
by: arun shankar | last post by:
hello iam unable to export entire crystal report that contains multiple pages ie. only partial data is being exported into excel sheet ... can u help me out ?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.