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

Using a query to populate a report.

I have a form with a command button on it that is supposed to open up a
report and use a query to populate it.

DoCmd.OpenReport "rptMailingList", acViewPreview, "qryMailingListChristmas"

qryMailingListChristmas sql:

SELECT DISTINCTROW tblClients.BillingName, tblClients.AccountType,
tblClients.BillingAddress, tblClients.Contact, tblClients.BillingCity,
tblClients.BillingState, tblClients.BillingZip,
Year([tblProjects].[StartDate]) AS Expr1
FROM tblClients INNER JOIN tblProjects ON tblClients.ClientID =
tblProjects.ClientID
WHERE (((tblClients.AccountType)="Residential") AND
((Year([tblProjects].[StartDate]))=Year(Date()))) ORDER BY
tblClients.BillingName;

If I run qryMailingListChristmas I get the results I expect. Returns all
residential clients with a project start date in the current year. If,
however, I use that command button on the form I am prompted to enter
tblProjects.StartDate. If I enter any date, the report opens showing all
Residential clients. What is going on here? Why am I even being promted to
enter a date?
Oct 29 '06 #1
4 3801
Jimmy wrote:
I have a form with a command button on it that is supposed to open up a
report and use a query to populate it.

DoCmd.OpenReport "rptMailingList", acViewPreview, "qryMailingListChristmas"

qryMailingListChristmas sql:

SELECT DISTINCTROW tblClients.BillingName, tblClients.AccountType,
tblClients.BillingAddress, tblClients.Contact, tblClients.BillingCity,
tblClients.BillingState, tblClients.BillingZip,
Year([tblProjects].[StartDate]) AS Expr1
FROM tblClients INNER JOIN tblProjects ON tblClients.ClientID =
tblProjects.ClientID
WHERE (((tblClients.AccountType)="Residential") AND
((Year([tblProjects].[StartDate]))=Year(Date()))) ORDER BY
tblClients.BillingName;

If I run qryMailingListChristmas I get the results I expect. Returns all
residential clients with a project start date in the current year. If,
however, I use that command button on the form I am prompted to enter
tblProjects.StartDate. If I enter any date, the report opens showing all
Residential clients. What is going on here? Why am I even being promted to
enter a date?

Go into View/Sort&Group off the menu. Is there a sort on a field that
doesn't exist on the report?
Oct 29 '06 #2
"Jimmy" <no**@none.comwrote in
news:e3*********************@fe10.news.easynews.co m:
I have a form with a command button on it that is supposed to
open up a report and use a query to populate it.

DoCmd.OpenReport "rptMailingList", acViewPreview,
"qryMailingListChristmas"

qryMailingListChristmas sql:

SELECT DISTINCTROW tblClients.BillingName,
tblClients.AccountType, tblClients.BillingAddress,
tblClients.Contact, tblClients.BillingCity,
tblClients.BillingState, tblClients.BillingZip,
Year([tblProjects].[StartDate]) AS Expr1 FROM tblClients INNER
JOIN tblProjects ON tblClients.ClientID = tblProjects.ClientID
WHERE (((tblClients.AccountType)="Residential") AND
((Year([tblProjects].[StartDate]))=Year(Date()))) ORDER BY
tblClients.BillingName;

If I run qryMailingListChristmas I get the results I expect.
Returns all residential clients with a project start date in
the current year. If, however, I use that command button on
the form I am prompted to enter tblProjects.StartDate. If I
enter any date, the report opens showing all Residential
clients. What is going on here? Why am I even being promted
to enter a date?
From your comments:
1) The query runs ok.
3) The report fails when launched by the form
Missing is #2. The report works/fails when run from the database
window.
I suspect that the problem is in the report, not the query nor
the method to launch it.

In general if an object like a form or report prompts for a
value, suspect that there is a typo somewhere in the form or
report., specifically with a call to the field that's being
asked for, or in the call to the underlying query of the form or
report. Could the report be calling an old version of the query?

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Oct 29 '06 #3

"Bob Quintal" <rq******@sPAmpatico.cawrote in message
>>
From your comments:
1) The query runs ok.
3) The report fails when launched by the form
Missing is #2. The report works/fails when run from the database
window.
The report runs fine from the database window as well. Perhaps a point of
interest, I'm not sure, but the underlying record source for the report is
qryClients while the query that the command button is attempting to use to
populate the report is qryMailingListChristmas, both of which are different
from the underlying query for the form itself. All three forms are,
however, variations of the same dataset.
I suspect that the problem is in the report, not the query nor
the method to launch it.

In general if an object like a form or report prompts for a
value, suspect that there is a typo somewhere in the form or
report., specifically with a call to the field that's being
asked for, or in the call to the underlying query of the form or
report. Could the report be calling an old version of the query?
See comment above about different queries. I'm not sure if that would play a
role. Also, I've checked each query and each call to those queries and there
are no mis-spellings.
Oct 29 '06 #4
"Jimmy" <no**@none.comwrote in
news:R1*********************@fe10.news.easynews.co m:
>
"Bob Quintal" <rq******@sPAmpatico.cawrote in message
>>>
From your comments:
1) The query runs ok.
3) The report fails when launched by the form
Missing is #2. The report works/fails when run from the
database window.

The report runs fine from the database window as well. Perhaps
a point of interest, I'm not sure, but the underlying record
source for the report is qryClients while the query that the
command button is attempting to use to populate the report is
qryMailingListChristmas, both of which are different from the
underlying query for the form itself. All three forms are,
however, variations of the same dataset.
>I suspect that the problem is in the report, not the query
nor the method to launch it.

In general if an object like a form or report prompts for a
value, suspect that there is a typo somewhere in the form or
report., specifically with a call to the field that's being
asked for, or in the call to the underlying query of the form
or report. Could the report be calling an old version of the
query?

See comment above about different queries. I'm not sure if
that would play a role. Also, I've checked each query and each
call to those queries and there are no mis-spellings.
is the field expr1 in your main query?

When you open a report using the filtername parameter, the
filter query has to include only the fields in the query that's
bound to the report. If you've added the field expr1, that will
cause your problem. It will not add the fields.

Add the expr1 to the qryClients that underlies the report, but
without the year(date()) in the criteria. that will fix your
problem.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Oct 30 '06 #5

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

Similar topics

9
by: (Pete Cresswell) | last post by:
I've got some SQL that works as far as returning a recordset from a series of UNION statements. viz: SELECT whatever UNION this UNION that UNION other
1
by: Mike Cooper | last post by:
Hi everyone, This is a tough one. I have a database full of solicitations, identifying a customer and recording initial call, first followup, second followup, etc. My boss want to be able to...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
0
by: Randall Arnold | last post by:
I have a Microsoft Access report (built on a SQL Server 2000 query) I have exported as xml/html. I include a stylesheet in the original export for formatting of the report. The schema is...
2
by: amith.srinivas | last post by:
Hi all, From a word macro in VBA, I am trying to create a report in access DB. The report is based on a query with a parameter. I am using Set rpt = Application.CreateReport rpt.RecordSource =...
17
by: Mr.Kane | last post by:
Here's my dilemma. I am putting together a trend report using PivotCharts and so the query that I am trying to construct basically would look at the "Date_Entered" for a record and if the "day"...
1
by: Mayhem05 | last post by:
I have an Access 2003 database that I need to write some VBA code for to populate a table. The table is based on a query I have built in Access queries. Right now I have 2 parameters that are...
5
by: John | last post by:
Hi I have a parameterised query for a report like this; PARAMETERS Event_ID Short; SELECT DISTINCTROW Events., ... FROM Events WHERE (((Events.)=)); Now I am trying to run the report...
3
by: vljones | last post by:
I have a report with sub reports. The sub reports are query based. The queries perform a Count. Where no data exists in the table, no results are provided. Is there a way to populate the sub...
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
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...
0
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,...
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.