473,387 Members | 1,891 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,387 software developers and data experts.

Report..Urgent!!

jrdn1st
Guys i created a simple Form with a button, Query & a Report, i want this button to call a Report that shows the Quert, how can i do so?
Oct 8 '06 #1

✓ answered by NeoPa

I too have found passing variables to a report to be very complicated.

To get around this I design the report to work in 2 ways :-
1. If the form is open - get info from there
2. If not - set your own defaults

In the code sample below, fraFrom is a frame on the form that is HOPED to be open

Expand|Select|Wrap|Line Numbers
  1.     On Error Resume Next
  2.     'If next line fails then intFrom stays 0 - otherwise it will be > 0
  3.     intFrom = Forms("frmName").fraFrom
  4.     On Error GoTo 0
  5.     If intFrom = 0 Then
  6.         'Form not there - set variables to your own defaults
  7.     Else
  8.         'Form there - set variables from form
  9.     End If
  10.     'Use variables set above to determine course of program...
  11.  
Another alternative is to set up access to global or static variables via a function interface.
It's a bit of a kludge but can be effective.
One drawback to this method is that it equally requires the data to be available at run time - therefore prepared previously.

I find the whole issue quite messy myself.

Just in case this can be helpful, I've included my function to do this but with no guarantees.

The calling code should call it with intSetGet set to 0 and a list of parameters to pass to a report.
The Report can use the variables by referencing as RptParms(n) where n refers to the nth parameter in the list.
Underlying queries can also reference them in the same way if required.

Expand|Select|Wrap|Line Numbers
  1. 'RptParms sets and returns a set of parameters required by a report.
  2. Public Function RptParms(intSetGet As Integer, _
  3.                          ParamArray avarParams() As Variant) As Variant
  4.     Static avarParms() As Variant
  5.     Dim intIdx As Integer
  6.  
  7.     RptParms = 0
  8.     If intSetGet = 0 Then
  9.         intSetGet = UBound(avarParams) + 1 - LBound(avarParams)
  10.         If intSetGet < 1 Then
  11.             ReDim avarParms(1 To 1)
  12.             avarParms(1) = "Error"
  13.             Exit Function
  14.         End If
  15.         ReDim avarParms(1 To intSetGet)
  16.         For intIdx = 1 To intSetGet
  17.             avarParms(intIdx) = avarParams(intIdx - 1)
  18.         Next intIdx
  19.     Else
  20.         'If outside bounds then it drops through and is set to "Error"
  21.         On Error Resume Next
  22.         If avarParms(intSetGet) = "Error" Then
  23.             RptParms = "Error"                  'On Error
  24.         Else
  25.             RptParms = avarParms(intSetGet)
  26.         End If
  27.     End If
  28. End Function
  29.  

5 1471
P.S: i want the report to show the query depending on the value chosen in the form, i have created a relation between 2 tables, now i need to retrieve the data in the report according to what is chosen in the form.
Oct 8 '06 #2
kdee
9
Put a query inside the report by using a subreport tool (in report designer).
Oct 18 '06 #3
lmawler
14
Hi,

I have some reports that work based on form input, and I handle them this way.

On the form, I have code for a button that opens the report. I set a global variable for my sql query. (I can't figure out how to pass a variable effectively to an opening report - openargs works but only for one variable? But I digress.)

Let's say your form has a field called "inputText", and a button called "GoReport."

In the general section (on the form), I declare my global variable:

public mySQLString as String

In the code for clicking the button (on the form), I put this code:

mySQLString = "Select * from MyTable where MyField like '*" & me("inputText") & "'"

doCmd.openReport("myReport"), acViewPreview

Note that if you want the report to print and not show on the screen, you can get rid of acViewPreview.

Then, on the report, I put in this code on the Open Report event like this:

dim myLocalSql as string
myLocalSql = Form_myForm.mySQLString

Reports!myReport.RecordSource = myLocalSql

You don't have to use a separate variable here (i.e., you can just call the global variable directly, but I have better luck tracing errors this way.)

I'm not a very advanced Access person, so this isn't terribly elegant, but I had a great deal of trouble getting this stuff to work, so I'm happy to share if it will save you some of the beating your head against the wall that I went through.

:-)
Lea Ann
Oct 18 '06 #4
NeoPa
32,556 Expert Mod 16PB
I too have found passing variables to a report to be very complicated.

To get around this I design the report to work in 2 ways :-
1. If the form is open - get info from there
2. If not - set your own defaults

In the code sample below, fraFrom is a frame on the form that is HOPED to be open

Expand|Select|Wrap|Line Numbers
  1.     On Error Resume Next
  2.     'If next line fails then intFrom stays 0 - otherwise it will be > 0
  3.     intFrom = Forms("frmName").fraFrom
  4.     On Error GoTo 0
  5.     If intFrom = 0 Then
  6.         'Form not there - set variables to your own defaults
  7.     Else
  8.         'Form there - set variables from form
  9.     End If
  10.     'Use variables set above to determine course of program...
  11.  
Another alternative is to set up access to global or static variables via a function interface.
It's a bit of a kludge but can be effective.
One drawback to this method is that it equally requires the data to be available at run time - therefore prepared previously.

I find the whole issue quite messy myself.

Just in case this can be helpful, I've included my function to do this but with no guarantees.

The calling code should call it with intSetGet set to 0 and a list of parameters to pass to a report.
The Report can use the variables by referencing as RptParms(n) where n refers to the nth parameter in the list.
Underlying queries can also reference them in the same way if required.

Expand|Select|Wrap|Line Numbers
  1. 'RptParms sets and returns a set of parameters required by a report.
  2. Public Function RptParms(intSetGet As Integer, _
  3.                          ParamArray avarParams() As Variant) As Variant
  4.     Static avarParms() As Variant
  5.     Dim intIdx As Integer
  6.  
  7.     RptParms = 0
  8.     If intSetGet = 0 Then
  9.         intSetGet = UBound(avarParams) + 1 - LBound(avarParams)
  10.         If intSetGet < 1 Then
  11.             ReDim avarParms(1 To 1)
  12.             avarParms(1) = "Error"
  13.             Exit Function
  14.         End If
  15.         ReDim avarParms(1 To intSetGet)
  16.         For intIdx = 1 To intSetGet
  17.             avarParms(intIdx) = avarParams(intIdx - 1)
  18.         Next intIdx
  19.     Else
  20.         'If outside bounds then it drops through and is set to "Error"
  21.         On Error Resume Next
  22.         If avarParms(intSetGet) = "Error" Then
  23.             RptParms = "Error"                  'On Error
  24.         Else
  25.             RptParms = avarParms(intSetGet)
  26.         End If
  27.     End If
  28. End Function
  29.  
Oct 19 '06 #5
Guys i created a simple Form with a button, Query & a Report, i want this button to call a Report that shows the Quert, how can i do so?
In the OnOpen Event of the report, use conditional code to change the recordSource of the report to alternative queries determined by your form
Oct 19 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Cantekin Guneser | last post by:
i am preparing a software for election system, this app need to show voters of each chest, i need help about crytal report that i have never used before, and i have few days, i generate data...
0
by: Daniel | last post by:
Hi ! I have problem in creating the crystal report with asp.net. I always face "Logon Failed !" message and failed to debug it. how to create the crystal report with the help of dataset ?? ...
1
by: Soren S. Jorgensen | last post by:
Hi, I've got a Crystal Report that gets some data from a stored procedure and I need to set some params of the proc at runtime. But no matter what I do, I cannot get the report to eat the params...
13
by: Niyazi | last post by:
Hi I have a report that I have to run it monthly in my machine. My code in VB.NET and I access AS400 to get data, anaysie it and send into pre formated Excel sheet. The data consist of 9000...
1
by: steve | last post by:
Hi All Can anybody point me to some info on creating a graph in VB.net 2005 report viewer I can't seem to find any on the web I want to show sales totals by week in a vertical bar graph ...
3
by: steve | last post by:
Hi All I have a VB.net 2005 app which uses MS Report Viewer to create reports Occassionally I get the following error when changing to a different report User code running on thread 196 has...
8
by: Ryan | last post by:
I have a SQL view that shows data by Category and Year - so the data may look something like this. Category - Year - Amount Fruit - 2006 - $12,000 Fruit - 2007 - $16,000 Vegetables - 2006 -...
4
by: ramaswamynanda | last post by:
Hello, I have an application in Access where I have developed about 10 reports. These have been working for a while and produce data properly. I recently tried exporting the report, from the...
6
by: martin DH | last post by:
**Urgent Need** I'll throw out the basics and any assistance is very, very, very much appreciated! Access 2003 on XP On a form (frmMain) is an option group of check boxes (ReportFrame) from...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.