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

Generate a Report according to parameters on a Form

I have a form where the user can enter 2 Parameters. Now i want to automatically generate a Report according to these parameters.

I'm making an SQL Statement and this needs to become the recordsource of the report.

Here is what i have done so far:


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPreviewReport_Click()
  2. On Error GoTo Err_cmdPreviewReport_Click
  3.  
  4. Dim ExpID As Long
  5.  
  6. ExpID = Nz(DLookup("[ExperimentID]", "qrySearchExperiment", "[SampleNumber] Like '* " & Me!txtSampleNrLow & "' AND [Organism] Like '*" & Me!txtOrganism & "*'"), 0)
  7.  
  8. Me!strSQLReport = "SELECT tblSamples.SampleNumber, tblSamples.SampleType, tblSamples.SampleDescription, tblExperiments.Organism, fktAvg(tblAnalysisData.absoluteNumberA,tblAnalysisData.absoluteNumberB,tblAnalysisData.absoluteNumberC) AS MeanCfu, fktMeanCtrl(tblAnalysisData.ExperimentID) AS MeanCtrl, fktActivity([MeanCtrl],[MeanCfu],tblSamples.Control) AS [Antimicrobial Activity]FROM tblExperiments INNER JOIN (tblSamples INNER JOIN tblAnalysisData ON tblSamples.SampleID = tblAnalysisData.SampleID) ON tblExperiments.ExperimentID = tblAnalysisData.ExperimentID"
  9. Me!strSQLReport = strSQLReport & " WHERE (((tblExperiments.ExperimentID) = " & ExpID & ")) ORDER BY tblSamples.SampleNumber"
  10.  
  11.  
  12. DoCmd.OpenReport "rptGenerated", acPreview
  13.  
  14. Exit_cmdPreviewReport_Click:
  15.     Exit Sub
  16.  
  17. Err_cmdPreviewReport_Click:
  18.     MsgBox Err.Description
  19.     Resume Exit_cmdPreviewReport_Click
  20.  
  21. End Sub
  22.  
  23.  

and:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. Me!RecordSource = Forms!("frmGenerateReport")!strSQLReport
  4.  
  5. End Sub
  6.  
I Get following error in the open event:

"Compile Error:
Type declaration character does not match declared data type"

Forms! is marked.

strSQLReport is a hidden field of the form. i can see, that i get the right SQL Statment.

I'm new to access, so don't now many basics. so can't i use Forms! in the open event of a report?

If not, how do i do this?
Nov 23 '07 #1
1 1412
puppydogbuddy
1,923 Expert 1GB
Try the syntax this way and see what happens:

Me.RecordSource = Forms!frmGenerateReport!strSQLReport

or like this

Me.RecordSource = Forms("frmGenerateReport").Controls(strSQLReport)
Nov 24 '07 #2

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

Similar topics

1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
8
by: Mark Flippin | last post by:
This is for a reporting problem using: Access 2000 SQL Server 2000 Both at SP3 I've a stored procedure in SQL Server 2000 which builds a result set from a disparate set of tables, utilizing...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
8
by: lauren quantrell | last post by:
When I open an Access form I can have no recordset specified, then in the form's OnOpen event I can do something like: Me.paramaters = "@SomeColumn = 22)" Me.recordsource = "dbo.sproc123" But I...
2
by: Bob | last post by:
I'm new to Access projects and SQL server and am not a veteran VB programmer. There's a cry for help! I'm attempting to print the current form on screen by using a command button which the user...
2
by: Denise | last post by:
How do I get the report to not spend time pulling up the data when I'm going to bail out of the report anyway? Below is the code in my report. I first show the user a form where they can select...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
0
by: rakeshc | last post by:
Hi, I am a new guy in jasper and iReport. I could create a report and subreport successfully with iReport. while running through iReport, it will ask for parameters and after supplying them,...
3
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.