473,403 Members | 2,338 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,403 software developers and data experts.

Query Based on Query

Hi there,

I have a query (QueryB) that is based on the results of another query
(QueryA).

When I open QueryB itself, it displays the exact records that I want. I
have a report based on QueryB, and when I open it directly, it displays
what I want. When I open the report from a command button on a form
using this code:

DoCmd.OpenReport "rpt_QueryB", acViewPreview, "QueryB"

...I get prompted for parameters.

Since I can open the query and the report itself without getting
prompted for parameters, why do I get prompted for them when I use
docmd.openreport? I don't want it to do this.

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
8 3231
Try just this

DoCmd.OpenReport "rpt_QueryB", acViewPreview

--
Wayne Morgan
Microsoft Access MVP
"Steven Stewart" <o6***@unb.ca> wrote in message
news:3f*********************@news.frii.net...
Hi there,

I have a query (QueryB) that is based on the results of another query
(QueryA).

When I open QueryB itself, it displays the exact records that I want. I
have a report based on QueryB, and when I open it directly, it displays
what I want. When I open the report from a command button on a form
using this code:

DoCmd.OpenReport "rpt_QueryB", acViewPreview, "QueryB"

..I get prompted for parameters.

Since I can open the query and the report itself without getting
prompted for parameters, why do I get prompted for them when I use
docmd.openreport? I don't want it to do this.

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #2
Hi there,

I tried "DoCmd.OpenReport "rpt_QueryB", acViewPreview" and this did work
(it didn't ask me for parameters), but now the problem has come back.
In actuality, I need to specify the where clause in this
docmd.openreport....so I have this:

"DoCmd.OpenReport "rpt_QueryB", acViewPreview,,strSQL"

...and yet again it is prompting me for parameters. Any thoughts?
Without the strSQL it won't prompt me for parameters, but I do need that
there. Here is strSQL:

strSQL = "((([subquery_YTD_Prov_A]![Province])='" & lstProvince.Value &
"') AND (([subquery_YTD_Prov_A]![Month])>= " & getMonth(lstMonth2.Value)
& " Or ([subquery_YTD_Prov_A]![Month])<=" & getMonth(lstMonths.Value) &
") AND (([subquery_YTD_Prov_A]![Year])>= " & txtStartYear & " Or
([subquery_YTD_Prov_A]![Year])<= " & txtYear & " ))"

Basically, I want the query to be based on values from the form. I want
the query to return values in a certain month/year range (i.e. 2/2002 to
4/2003) and I want the province specified.

Thansk for any help!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
Steven Stewart <o6***@unb.ca> wrote in
news:3f*********************@news.frii.net:
Hi there,

I tried "DoCmd.OpenReport "rpt_QueryB", acViewPreview" and
this did work (it didn't ask me for parameters), but now the
problem has come back. In actuality, I need to specify the
where clause in this docmd.openreport....so I have this:

"DoCmd.OpenReport "rpt_QueryB", acViewPreview,,strSQL"

..and yet again it is prompting me for parameters. Any
thoughts? Without the strSQL it won't prompt me for
parameters, but I do need that there. Here is strSQL:

strSQL = "((([subquery_YTD_Prov_A]![Province])='" &
lstProvince.Value & "') AND (([subquery_YTD_Prov_A]![Month])>=
" & getMonth(lstMonth2.Value) & " Or
([subquery_YTD_Prov_A]![Month])<=" & getMonth(lstMonths.Value)
& ") AND (([subquery_YTD_Prov_A]![Year])>= " & txtStartYear &
" Or ([subquery_YTD_Prov_A]![Year])<= " & txtYear & " ))"
You have a bunch of parameters in strSQL that the jet engine cannot
resolve, because your where clause is all messed up.

strSQL =
"[subquery_YTD_Prov_A].[Province]='" _
& me.lstProvince.Value & _
& "' " _
& "AND [subquery_YTD_Prov_A].[Month] >= " _
& getMonth(me.lstMonth2.Value) _
& " AND [subquery_YTD_Prov_A].[Month] <= "
& getMonth(me.lstMonths.Value) _
& " AND [subquery_YTD_Prov_A].[Year] >= " _
& me.txtStartYear _
& " AND [subquery_YTD_Prov_A].[Year] <= "
& me.txtYear

should work a lot better.

You had ! separators where . is required and no proper form
identifiers (me.), plus a whole lot of useless parentheses.

You also had some OR statements that really want to be AND
statements.

Bob Q.


Basically, I want the query to be based on values from the
form. I want the query to return values in a certain
month/year range (i.e. 2/2002 to 4/2003) and I want the
province specified.

Thansk for any help!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #4
Thanks for the syntax lesson!..yes that, indeed, solves it, and I have
learned! This is, obviously, new stuff for me. Thanks again..

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5
Steven Stewart <o6***@unb.ca> wrote in message news:<3f*********************@news.frii.net>...
Hi there,

I tried "DoCmd.OpenReport "rpt_QueryB", acViewPreview" and this did work
(it didn't ask me for parameters), but now the problem has come back.
In actuality, I need to specify the where clause in this
docmd.openreport....so I have this:

"DoCmd.OpenReport "rpt_QueryB", acViewPreview,,strSQL"

..and yet again it is prompting me for parameters. Any thoughts?
Without the strSQL it won't prompt me for parameters, but I do need that
there. Here is strSQL:

strSQL = "((([subquery_YTD_Prov_A]![Province])='" & lstProvince.Value &
"') AND (([subquery_YTD_Prov_A]![Month])>= " & getMonth(lstMonth2.Value)
& " Or ([subquery_YTD_Prov_A]![Month])<=" & getMonth(lstMonths.Value) &
") AND (([subquery_YTD_Prov_A]![Year])>= " & txtStartYear & " Or
([subquery_YTD_Prov_A]![Year])<= " & txtYear & " ))"

Basically, I want the query to be based on values from the form.
you have to reference the WHOLE "path" to the control you're
referencing, not just the control itself. the Control is on a form (in
that form's controls collection), which is in the forms collection...

Forms![MyForm]![MyControlOnMyForm]
strSQL = "((([subquery_YTD_Prov_A]![Province])='" & [FORMS]![MYFORM]!lstProvince.Value &
"') AND (([subquery_YTD_Prov_A]![Month])>= " & getMonth([FORMS]![MYFORM]!lstMonth2.Value)
& " Or ([subquery_YTD_Prov_A]![Month])<=" & getMonth([FORMS]![MYFORM]!lstMonths.Value) &
") AND (([subquery_YTD_Prov_A]![Year])>= " & txtStartYear & " Or
([subquery_YTD_Prov_A]![Year])<= " & txtYear & " ))"

Nov 12 '05 #6
Hi there,

Although I said it worked, I was mistaken. I had something REMed out
that shouldn't have been, making me think it had worked. So I tried
what was suggested:

strSQL =
"[subquery_YTD_Prov_A].[Province]='" _
& me.lstProvince.Value & _
& "' " _
& "AND [subquery_YTD_Prov_A].[Month] >= " _
& getMonth(me.lstMonth2.Value) _
& " AND [subquery_YTD_Prov_A].[Month] <= "
& getMonth(me.lstMonths.Value) _
& " AND [subquery_YTD_Prov_A].[Year] >= " _
& me.txtStartYear _
& " AND [subquery_YTD_Prov_A].[Year] <= "
& me.txtYear
DoCmd.OpenReport "rpt_YTD_By_Province", acViewPreview,
"subquery_YTD_Prov_B", strSQL

...and I still get prompted for parameters (subquery_YTD_Prov_A.Month
and .Year).

Why would it prompt me for those values when it is getting those values
in the code? I tried Val(me.txtYear) but that makes no difference.

What I have is a query (subquery_YTD_Prov_A) that works fine. Every
record returned in that query has a Month, Year, and Province field.
For the query I am doing ON that query, I want to only return the
records of a specific date range (month/year to month/year) for a
specific province. It's worth noting that it does not prompt me for the
province parameter....only the Month and Year.

I have named this second query "subquery_YTD_Prov_B" and if I open the
object directly, it works fine, but with the docmd from code it is not
working fine.

That is what I am trying to do, but I don't understand why I am getting
prompted for parameters still. Thanks again for any assistance.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #7
Have you tried "hard coding" numbers in as a test instead of using the
references to the form's controls?

--
Wayne Morgan
Microsoft Access MVP
"Steven Stewart" <o6***@unb.ca> wrote in message
news:3f*********************@news.frii.net...
Hi there,

Although I said it worked, I was mistaken. I had something REMed out
that shouldn't have been, making me think it had worked. So I tried
what was suggested:

strSQL =
"[subquery_YTD_Prov_A].[Province]='" _
& me.lstProvince.Value & _
& "' " _
& "AND [subquery_YTD_Prov_A].[Month] >= " _
& getMonth(me.lstMonth2.Value) _
& " AND [subquery_YTD_Prov_A].[Month] <= "
& getMonth(me.lstMonths.Value) _
& " AND [subquery_YTD_Prov_A].[Year] >= " _
& me.txtStartYear _
& " AND [subquery_YTD_Prov_A].[Year] <= "
& me.txtYear
DoCmd.OpenReport "rpt_YTD_By_Province", acViewPreview,
"subquery_YTD_Prov_B", strSQL

..and I still get prompted for parameters (subquery_YTD_Prov_A.Month
and .Year).

Why would it prompt me for those values when it is getting those values
in the code? I tried Val(me.txtYear) but that makes no difference.

What I have is a query (subquery_YTD_Prov_A) that works fine. Every
record returned in that query has a Month, Year, and Province field.
For the query I am doing ON that query, I want to only return the
records of a specific date range (month/year to month/year) for a
specific province. It's worth noting that it does not prompt me for the
province parameter....only the Month and Year.

I have named this second query "subquery_YTD_Prov_B" and if I open the
object directly, it works fine, but with the docmd from code it is not
working fine.

That is what I am trying to do, but I don't understand why I am getting
prompted for parameters still. Thanks again for any assistance.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #8

Hard-coding in the numbers made no difference. It still prompted me for
parameters.

For testing purposes, I simplified it down to setting the criteria for
just one field: Province...

------
strSQL = "[subquery_Prov_A]![Province] = '" & lstProvince.Value & "'"

DoCmd.OpenReport "rpt_YTD_By_Province", acViewPreview, subquery_Prov_B,
strSQL
-------

When I run this, I always get prompted for the parameter
"subquery_Prov_A!Province".

If I go directly to the queries design view and "hard-code" the criteria
into subquery_Prov_A and then open up subquery_Prov_B, it works
perfectly; however, I need to set the criteria based on form controls
before opening the report from code.

Now, even if I try...

strSQL = "[subquery_Prov_A]![Province] = 'British Columbia'"

...I still get prompted for that parameter.

So, this simply may not be possible to do.

Alas, I just realized that I could refer to the form controls directly
from the field's criteria in design view. Problem solved!

Thanks for all the help out there.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #9

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

Similar topics

0
by: John Macon | last post by:
------=_NextPart_000_04B4_01C36308.415CE100 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, Long time reader, first time poster, I hope...
4
by: sci | last post by:
Could someone help me by answering the questions below? What's a cursor? What's difference between Query and View? Is a RecordSet just part of a table? Can it be part of a query of view? If...
2
by: seansan | last post by:
Hi, suppose I have one report that reports some data to me based on a functional area that I define. We have about 20 func_areas and every time the report is the same. Is there some way to have...
2
by: neptune | last post by:
I have a query where each customer has an or . Sometimes both fields for a customer are populated, but if is null, then will be populated and vice versa. I have a form, , where I select a...
1
by: Robert | last post by:
I am trying to create a db for service providers by county. I'm relatively new to db programming, but I have done quite a bit of programming ranging from the old basic days up to doing some...
2
by: dskillingstad | last post by:
I'm trying to set up a parameter query based on an unbound form. This search form has about 5 text boxes where the user can type in values within each box and search a specific table based on the...
4
by: Marc DVer | last post by:
As a simple example, say there is table 'namelist' with column 'names' as char(20). I would like to do something akin to: select namelist.names as mynames, left(mynames,2) as initials; In...
6
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor...
4
by: john | last post by:
I created a form via the wizard with 1 main table and 2 one-on-one tables. As i couldn't add a field to the form (a field that I added to the table after creating the form), I googled out that the...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.