473,549 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call report based on UDF with parameters

7 New Member
I create in Access report based on user defined function(UDF) in SQL Server which returns table.

CREATE FUNCTION MyFunc_VP (@VP varchar(12))
RETURNS TABLE
AS
RETURN (SELECT......

In Access, I am calling a report with DoCmd.OpenRepor t method.

DOCMD.OpenRepor t stDocName, acPreview

How to call report passing a parameter from form (Forms!FormName !TextBox)
(solution with where clause doesn't match my problem).
Mar 31 '08 #1
13 3220
JConsulting
603 Recognized Expert Contributor
have you tried using the report's filter option?
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]
wherecondition = A string expression that's a valid SQL WHERE clause without the word WHERE.
Expand|Select|Wrap|Line Numbers
  1. DOCMD.OpenReport stDocName, acPreview,,"[somefield] = " & Forms!FormName!TextBox
Apr 1 '08 #2
masteraccess2008
7 New Member
have you tried using the report's filter option?

DoCmd.OpenRepor t reportname[, view][, filtername][, wherecondition]

wherecondition = A string expression that's a valid SQL WHERE clause without the word WHERE.



DOCMD.OpenRepor t stDocName, acPreview,,"[somefield] = " & Forms!FormName! TextBox

Thank you, but..
in Access Report i use user defined function(UDF) instead of query. Parameters in UDF has no relation with where part of SQL statement, so your solution doens't work for me. Is the any other way to pass parameters calling report?
Apr 1 '08 #3
NeoPa
32,564 Recognized Expert Moderator MVP
Can you show what you are using.
I can't understand why the Filter would not work, even for a T-SQL UDF.

You have tried it haven't you?
Apr 3 '08 #4
masteraccess2008
7 New Member
Can you show what you are using.
I can't understand why the Filter would not work, even for a T-SQL UDF.

You have tried it haven't you?

My steps were as follows:
1. Create in SQL Server 2000 UDF:
CREATE FUNCTION TEMP_VP (@VP varchar(12))
RETURNS TABLE
AS
RETURN.......
2. In Access open new project using existing data
3. Create Report named "MyReport" based on function TEMP_VP
When i Start this report program ask me: Enter Parameter Value / VP
4. Create new form with text field "FormField" and call report from this form:
Dim stDocName As String
Dim WhereC As String
stDocName = "MyReport"
WhereC = "[VP] = " + Form!FormField
DoCmd.OpenRepor t stDocName, acPreview, , WhereC
5. When i call report, program still ask me Enter Parameter Value/VP and reports "Invalid Column Name VP".

How to solve this problem?
Apr 4 '08 #5
NeoPa
32,564 Recognized Expert Moderator MVP
When you run TEMP_VP as a simple Access query, what columns (exactly) are returned?

What is some example data for [VP]?
Apr 4 '08 #6
masteraccess2008
7 New Member
When you run TEMP_VP as a simple Access query, what columns (exactly) are returned?

What is some example data for [VP]?
TEMP_VP is really very simple query:
Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION TEMP_VP (@VP varchar(12))
  2. RETURNS TABLE
  3. AS
  4. RETURN (SELECT MAX(KODA_VP) AS KODA_vp,MIN(PRICE) AS MINp,MAx(PRICE) AS Maxp FROM SJ_PRICES WHERE KODA_VP=@vp)
example of data for VP: "GOOG"

This function is prepared only for this forum, in real solution function is much more complex..
Apr 7 '08 #7
NeoPa
32,564 Recognized Expert Moderator MVP
I'd really much rather you answered my question than giving me some SQL to look through - especially T-SQL.

However, from looking at your code I can see two major problems with your test of the filter (WhereC = "[VP] = " + Form!FormField) :
  1. [VP] is not a field that is returned in your function (SQL).
    You have fields called [KODA_vp], [MINp] & [Maxp] only.
  2. [VP] is a text field so the filter would need to include single quotes around the value.
    Expand|Select|Wrap|Line Numbers
    1. WhereC = "[VP] = '" + Form!FormField & "'"
I would suggest a filter is still the best option for you. I'd be happy to help further if you have any questions.
Apr 7 '08 #8
masteraccess2008
7 New Member
I'd really much rather you answered my question than giving me some SQL to look through - especially T-SQL.

However, from looking at your code I can see two major problems with your test of the filter (WhereC = "[VP] = " + Form!FormField) :
  1. [VP] is not a field that is returned in your function (SQL).
    You have fields called [KODA_vp], [MINp] & [Maxp] only.
  2. [VP] is a text field so the filter would need to include single quotes around the value.
    Expand|Select|Wrap|Line Numbers
    1. WhereC = "[VP] = '" + Form!FormField & "'"
I would suggest a filter is still the best option for you. I'd be happy to help further if you have any questions.
Answers to your questions:
Query returns: KRKG 6.21 126.58
Value of Parameter: 'GOOG'

I ran code just like you suggest:
Expand|Select|Wrap|Line Numbers
  1.  Dim WhereC As String
  2.     stDocName = "MyReport"
  3.     WhereC = "[VP] = '" + Form!FormField & "'"
  4.     DoCmd.OpenReport stDocName, acPreview, WhereC
When I run this code (Form!FormField is of course filled in) program stil ask me "Enter Parameter Value".
I'm very unhappy about this.
Apr 8 '08 #9
NeoPa
32,564 Recognized Expert Moderator MVP
You have fixed the problem numbered #2 in my post but #1 is still an issue for you. You are trying to select on a field ([VP]) which doesn't exist as far as I can tell.
When you run TEMP_VP as a simple Access query, what columns (exactly) are returned?

What is some example data for [VP]?
This is a quote of my post (#6) where I asked the questions. I am actually interested in the column names rather than any example data in them.

The second question you've already answered quite adequately.
The first I think I know from your posted SQL but it would be interesting to have this confirmed.
Apr 9 '08 #10

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

Similar topics

1
17646
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
1
2061
by: Fred Zuckerman | last post by:
I have 8 reports that I want to run. Each report is only about 6-7 lines long. I'd like to get them all on a single page. So I created a parent report and made each of the 8 desired reports a sub-report. That part all works fine. My problem is that each of the 8 sub-reports is based on a different query. Each of the 8 queries has 2...
6
3311
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a parameter query which is the recordsource for the report. The parameter is <=. The query returns the correct amounts upto the date entered (no need for...
15
4388
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 of students and columns of activities and the data are the students' scores in each activity. No problem, almost. The problem is that there are...
8
10750
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 can't do this in a report as it will prompt me for the parameters, even though they seem to be defined ahead of the recordsource. I have worked...
3
3409
by: Bryan | last post by:
I've been looking over this newsgroup, but I can't find an answer to my problem. I see that a few others have posted this issue over the years, but none of them got a response. I'll give it another shot. I have a report that is based on a crosstab query. The crosstab query is based off of another query, and that has a parameter in the...
2
5965
by: nqtrung | last post by:
Hi all! I want to create a report generator: The user should enter in a web page the parameters for the report (using JSP) and press 'Generate report'. As the result: the right data should be extract from the DB and a report should be generated. I know how to create a report in the "Seagate Crystal Report". but what I need to create is a...
5
5290
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the user prompted for them). Based on a Microsoft page (http://support.microsoft.com/kb/287437), I tried the following approach: Private Sub...
3
2056
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few parameters...." I have read many articles on the web about how to make a dynamic report based on a cross-tab query. But for some reason mine never...
0
7524
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6048
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.