By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Prompted for parameter on OpenReport

P: n/a
Hello,

I'm trying to limit a report to a list of parameters that I pass in.
The report and the underlying query both use the column FirstName.
Whenever I try to limit the FirstName in via the "Where" clause, I get
prompted to input the FirstName parameter, even though I'm passing it
in via OpenReport

The syntax I tried using:

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = ""John"")"

-- And --

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = 'John')"

My sql query is
select firstname, lastname from employee

I've poured through a ton of newsgroup postings related to OpenReport
and haven't come up with a solution. I have tried many variations on
the syntax, and tried using filters instead, but I keep getting
prompted to give a FirstName. Even when I do give a valid FirstName,
the query isn't limited and I keep getting a complete list of
employees.

Is there some other area in Access that I should be troubleshooting
besides the OpenReport syntax?

Thanks in advance for any help you can provide.

Aaron
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
My guess is, the filter you are trying to pass to the OpenReport is not
based on the data source for the report, as it is apparently a query,
not the Employees table.
Why not place the criteria into the source query in the first place:

select firstname, lastname from employee where firstname = "John"

and use this SQL as the report's data source?
If you have to define the filter at runtime, you have options: in 2002,
you can use OpenArgs; in earlier you have to use the report's Open event
to obtain the filtering criteria.
Pavel

Aaron wrote:

Hello,

I'm trying to limit a report to a list of parameters that I pass in.
The report and the underlying query both use the column FirstName.
Whenever I try to limit the FirstName in via the "Where" clause, I get
prompted to input the FirstName parameter, even though I'm passing it
in via OpenReport

The syntax I tried using:

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = ""John"")"

-- And --

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = 'John')"

My sql query is
select firstname, lastname from employee

I've poured through a ton of newsgroup postings related to OpenReport
and haven't come up with a solution. I have tried many variations on
the syntax, and tried using filters instead, but I keep getting
prompted to give a FirstName. Even when I do give a valid FirstName,
the query isn't limited and I keep getting a complete list of
employees.

Is there some other area in Access that I should be troubleshooting
besides the OpenReport syntax?

Thanks in advance for any help you can provide.

Aaron

Nov 12 '05 #2

P: n/a
Aaron,

DoCmd.OpenReport "ShowEmployees", acViewNormal, ,"[firstname] = 'John'"

Why are you hard coding this?
Do you intend to recode each time you want a report with a different first
name?

The simplest way is to just change the query:
SELECT Employee.FirstName, Employee.LastName
FROM Employee
WHERE Employee.FirstName =[Enter First Name];

Then run the report.

You'll be prompted for the name when you open the report.

If you have a form displaying the employee records, then you would use:
Docmd.OpenReport "ShowEmployees", acViewNormal, , "[FirstName] = '" &
Me![FirstName] & "'"

Whatever the [FirstName] is that is on the record displayed on the form will
be the one filtered in the report.
John Smith, John Anderson, John Jones, etc.
In this case do not use the query criteria.
--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
"Aaron" <de****************@hotmail.com> wrote in message
news:c5**************************@posting.google.c om...
Hello,

I'm trying to limit a report to a list of parameters that I pass in.
The report and the underlying query both use the column FirstName.
Whenever I try to limit the FirstName in via the "Where" clause, I get
prompted to input the FirstName parameter, even though I'm passing it
in via OpenReport

The syntax I tried using:

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = ""John"")"

-- And --

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = 'John')"

My sql query is
select firstname, lastname from employee

I've poured through a ton of newsgroup postings related to OpenReport
and haven't come up with a solution. I have tried many variations on
the syntax, and tried using filters instead, but I keep getting
prompted to give a FirstName. Even when I do give a valid FirstName,
the query isn't limited and I keep getting a complete list of
employees.

Is there some other area in Access that I should be troubleshooting
besides the OpenReport syntax?

Thanks in advance for any help you can provide.

Aaron

Nov 12 '05 #3

P: n/a
how or where did you try to run this from? I generically recreated
what you say you did, and I didn't have any trouble. Here is what I
did:
1. I created a table 'zz' with an Id, fname, & lname fields. I entered
ONE entry: fname = 'scott', lname = 'bradley'.

2. I created a query 'qz' to queries all 3 fields from 'zz'
3. I created a report 'showEmployees' based on 'qz'
4. I then created in funtion in module1, called 'showReport' [this is
where I'm wondering how/where you are calling 'OpenReport']

5. the function has this one statement:
doCmd.OpenReport "showEmployees", acViewPreview,, "([zz].[fname] =
""scott"")"
6. I then created a macro 'a' with only one action, "RunCode" with the
function name showReport().
7. after executing the macro, I got a preview of the report with all
three fields shown: id = 1, fname=scott, lname=bradley

So, we probably need more info about how you are executing
'OpenReport'.

-PT

de****************@hotmail.com (Aaron) wrote in message news:<c5**************************@posting.google. com>...
Hello,

I'm trying to limit a report to a list of parameters that I pass in.
The report and the underlying query both use the column FirstName.
Whenever I try to limit the FirstName in via the "Where" clause, I get
prompted to input the FirstName parameter, even though I'm passing it
in via OpenReport

The syntax I tried using:

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = ""John"")"

-- And --

DoCmd.OpenReport "ShowEmployees", acViewNormal,
,"([employee].[firstname] = 'John')"

My sql query is
select firstname, lastname from employee

I've poured through a ton of newsgroup postings related to OpenReport
and haven't come up with a solution. I have tried many variations on
the syntax, and tried using filters instead, but I keep getting
prompted to give a FirstName. Even when I do give a valid FirstName,
the query isn't limited and I keep getting a complete list of
employees.

Is there some other area in Access that I should be troubleshooting
besides the OpenReport syntax?

Thanks in advance for any help you can provide.

Aaron

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.