472,371 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Stacked crosstab query - dynamically update columns

I have a crosstab query that compiles data for Months of the year. I
have a stacked select query on top of that crosstab query that uses
the latest 2 months data and exports it to a fixed length flat file.
Ideally I would like to be able to just select the Last 2 Columns of
the Crosstab query as inputs to the Select query WITHOUT having to go
in month after month and manually change it...

I may be asking a bit much here but is there a way to make this
happen?? I.e. this month we would be using the columns [0704] and
[0705] and next month we would use [0705] and [0706] because we would
have a new months worth of data injected into the original tables.

The only reason I want this is because these queries do a heck of a
lot of heavy lifting and they are slugs to open/modify/save so I'd
prefer to just have to export it.

Any help is greatly appreciated!

May 28 '07 #1
4 6363

"m.wanstall" <m.********@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
I have a crosstab query that compiles data for Months of the year. I
have a stacked select query on top of that crosstab query that uses
the latest 2 months data and exports it to a fixed length flat file.
Ideally I would like to be able to just select the Last 2 Columns of
the Crosstab query as inputs to the Select query WITHOUT having to
go
in month after month and manually change it...

I may be asking a bit much here but is there a way to make this
happen?? I.e. this month we would be using the columns [0704] and
[0705] and next month we would use [0705] and [0706] because we
would
have a new months worth of data injected into the original tables.

The only reason I want this is because these queries do a heck of a
lot of heavy lifting and they are slugs to open/modify/save so I'd
prefer to just have to export it.

Any help is greatly appreciated!
m.wanstall,

Crosstab queries create dynamic column names based on the values of a
column in a table.

Every time such a query runs, the column names may be different.

You want to create a special query that dynamically reconfigures
itself so that it can always pick out the "correct" columns from the
ever-changing results of the crosstab.

The bad news is that there is no easy way to do that.

I can think of a way to alter your "second query" dynamically via VBA,
but it would be pointlessly complicated.

I recommend creating a VBA routine that is based on creating a
recordset using the crosstab query in question.

Using VBA, you can dynamically extract only the "last two months"
columns in the recordset and put the data into a new table you create
in the VBA code. Then run your "second query" on the new table. This
way, you never need to change your "second query".

There are various things you can do with this "intermediate" table.

You can delete it every time you run the VBA code so that it is out of
the way. You also can rename the last used "new table" by appending
the date and time (if the table actually exists) at the beginning of
your VBA code so that you keep several past copies. The second option
allows you to keep a generational history of the information you are
drawing on, so you have it later, but it also takes up more space.
Possibly Unnecessary Commentary:

I recommend examining your db schema for possible redesign of your
crosstab query, second query (with an eye to eliminating it), and
possibly the whole db. You shouldn't have to use this type of
indirection (using VBA to create intermediate quasi-temporary tables)
if your db and queries are designed correctly. That goes far beyond
the scope of your question, though.
Sincerely,

Chris O.
May 29 '07 #2
"m.wanstall" <m.********@gmail.comwrote in
news:11**********************@w5g2000hsg.googlegro ups.com:
I have a crosstab query that compiles data for Months of the
year. I have a stacked select query on top of that crosstab
query that uses the latest 2 months data and exports it to a
fixed length flat file. Ideally I would like to be able to
just select the Last 2 Columns of the Crosstab query as inputs
to the Select query WITHOUT having to go in month after month
and manually change it...

I may be asking a bit much here but is there a way to make
this happen?? I.e. this month we would be using the columns
[0704] and [0705] and next month we would use [0705] and
[0706] because we would have a new months worth of data
injected into the original tables.

The only reason I want this is because these queries do a heck
of a lot of heavy lifting and they are slugs to
open/modify/save so I'd prefer to just have to export it.

Any help is greatly appreciated!
How about taking the datediff() between date() and datefield
this will give column headers of -3,-2,-1, 0 for the last three
and the current months?

I use a set of calculated labels on a form or report to reverse
the process and show the correct period.Use the dateadd()
function.


--
Bob Quintal

PA is y I've altered my email address.

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

May 29 '07 #3
I'd reccomend not using a handicapped database

move to SQL Server
"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
"m.wanstall" <m.********@gmail.comwrote in
news:11**********************@w5g2000hsg.googlegro ups.com:
>I have a crosstab query that compiles data for Months of the
year. I have a stacked select query on top of that crosstab
query that uses the latest 2 months data and exports it to a
fixed length flat file. Ideally I would like to be able to
just select the Last 2 Columns of the Crosstab query as inputs
to the Select query WITHOUT having to go in month after month
and manually change it...

I may be asking a bit much here but is there a way to make
this happen?? I.e. this month we would be using the columns
[0704] and [0705] and next month we would use [0705] and
[0706] because we would have a new months worth of data
injected into the original tables.

The only reason I want this is because these queries do a heck
of a lot of heavy lifting and they are slugs to
open/modify/save so I'd prefer to just have to export it.

Any help is greatly appreciated!

How about taking the datediff() between date() and datefield
this will give column headers of -3,-2,-1, 0 for the last three
and the current months?

I use a set of calculated labels on a form or report to reverse
the process and show the correct period.Use the dateadd()
function.


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com
Jun 25 '07 #4
"Tom Wickerqueer" <tw@ewu.eduwrote in news:OQtGdKwtHHA.488
@TK2MSFTNGP04.phx.gbl:
I'd reccomend not using a handicapped database

move to SQL Server
What has SQL server got to do with this? -Nothing.
Go away, Don;t go away mad, just go away. [plonk]

>

"Bob Quintal" <rq******@sPAmpatico.cawrote in message
news:Xn**********************@66.150.105.47...
>"m.wanstall" <m.********@gmail.comwrote in
news:11**********************@w5g2000hsg.googlegr oups.com:
>>I have a crosstab query that compiles data for Months of the
year. I have a stacked select query on top of that crosstab
query that uses the latest 2 months data and exports it to a
fixed length flat file. Ideally I would like to be able to
just select the Last 2 Columns of the Crosstab query as
inputs
>>to the Select query WITHOUT having to go in month after
month
>>and manually change it...

I may be asking a bit much here but is there a way to make
this happen?? I.e. this month we would be using the columns
[0704] and [0705] and next month we would use [0705] and
[0706] because we would have a new months worth of data
injected into the original tables.

The only reason I want this is because these queries do a
heck
>>of a lot of heavy lifting and they are slugs to
open/modify/save so I'd prefer to just have to export it.

Any help is greatly appreciated!

How about taking the datediff() between date() and datefield
this will give column headers of -3,-2,-1, 0 for the last
three
>and the current months?

I use a set of calculated labels on a form or report to
reverse
>the process and show the correct period.Use the dateadd()
function.


--
Bob Quintal

PA is y I've altered my email address.

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



--
Bob Quintal

PA is y I've altered my email address.

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

Jun 25 '07 #5

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

Similar topics

3
by: Darleen | last post by:
I am seeking conceptual here on how to get started with a "3D Matrix" in Access. We run a training center which holds multiple classes in multiple cities at multiple times. So I need to create a...
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...
0
by: Richard Hollenbeck | last post by:
I have a crosstab query that shows all the scores of all the activities of all the students in all courses, with the students being in the rows and the activities being in the columns and the...
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
2
by: scott.k.fraley | last post by:
....and the SELECT thats trying to pull from said Query doesn't like it one bit! ;) I'm working on this project (in Access 2002) and there is a report who's RecordSource is the following...
8
by: Penny | last post by:
(Access 2003 Multiuser Split DB, Windows XP Pro) Hi All, I would really appreciate just some basic tips on how to make a Crosstab Form based on a Crosstab Query. The query always has the same...
13
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
4
by: mattlightbourn | last post by:
Hi all, I have a problem which has been driving me nuts. Crosstab queries! I have a database witch a few different tables to do with garment manufacturing. I have a table for a client...
8
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. ...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.