473,466 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access 2003 crosstab query where criteria as increment

20 New Member
Hi,

I have some code below in VBA for Access 2003 which is on a button called "RentalCrosstabPercTtlQtyMonthLoc_Click". This is a crosstab query which brings up rental items down the side, who rents along the top, the rental month and total number of each item on that month as rows next to the item, something like this:

Item TotalQty Month Renter1 Renter2 ....
PC 234 Aug-2007 2.33 4.55

The values for renter are worked out in the crosstab query, but how isnt important here (as it will waste space explaining!!). Here is the code:

Dim db As dao.Database
Dim rs As dao.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select * From Location", dbOpenSnapshot)

While Not rs.EOF
DoCmd.OutputTo acOutputQuery, "Rental_CrossTab_PercentageOfTotalQtyByLocatio n", "MicrosoftExcel(*.xls)", "C:\Documents ........\Rental Crosstab - " & rs!Location & " - " & Format(Now(), "dd-mmm-yy") & ".xls", True
Wend

rs.Close

There are 5 different locations, and at the moment the crosstab query brings up all rentals for all locations. What I need to be able to do is put in an increment in the crosstab query (in design view as criteria for a where) for location, which references the location table, and then have the locID (see below) put into the rs!Location in above code so the rentals for location 1, say, are saved, and then location 2 saved separately in a different excel spreadsheet.

The location table is made up of 2 columns (headings being LocID and Loc), with locID being numbers, and loc as the relevant name to the locID.

Many thanks in advance for help, I've tried looking on the net, and on this site, and couldn't find any information.

Andy
Oct 5 '07 #1
4 2474
nico5038
3,080 Recognized Expert Specialist
I miss the needed rs.movenext in your WHILE-loop:

Expand|Select|Wrap|Line Numbers
  1. Dim db As dao.Database
  2. Dim rs As dao.Recordset
  3. Set db = CurrentDb()
  4. Set rs = db.OpenRecordset("Select * From Location", dbOpenSnapshot)
  5.  
  6. While Not rs.EOF
  7.   DoCmd.OutputTo acOutputQuery, "Rental_CrossTab_PercentageOfTotalQtyByLocation", "MicrosoftExcel(*.xls)", "C:\Documents ........\Rental Crosstab - " & rs!Location & " - " & Format(Now(), "dd-mmm-yy") & ".xls", True
  8.   rs.movenext
  9. Wend
  10.  
  11. rs.Close
  12.  
Nic;o)
Oct 5 '07 #2
rdsandy
20 New Member
Just to maybe explain it a little more, if for example I stuck 1 in the where criteria (locID being 1 and loc then being london), the crosstab query shows the results for london, and then puts london in place of the rs!Location (as it puts 1 into it, but puts the relevant location instead of the number).

Im sure you know but the query design is like:

Field: LocID
Table: Location
Total: Where
Crosstab: (not shown) - blank as not needed to be shown
Sort: left blank
Criteria: where the answer will eventually go

Many thanks again.

Andy
Oct 5 '07 #3
rdsandy
20 New Member
oh yes sorry, that does need to be in there!
Oct 5 '07 #4
nico5038
3,080 Recognized Expert Specialist
The loop however won't solve the selection for a particular location, as I see just the same query being used, without a location selection in a WHERE clause....
Is creating the same pivot table for all locations OK, or do you need just that location?

Nic;o)
Oct 5 '07 #5

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

Similar topics

4
by: Michael John | last post by:
Dear Oracle Developers, my task is to make up a Oracle View from a Pivot table in MS Access. Given are two tables to join: T_FIRM: FIRM_ABBR VARCHAR2(3 BYTE), FIRM_LONG ...
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...
1
by: Brad | last post by:
Thanks for taking the time to read my question. I have a table of data that has Date, Data and Category. I need to show, in a report, each Categories Data by Date. The Date has to be it's own...
3
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
4
by: torontolancer | last post by:
Hi there how r u .I would really appriciate ur concern regarding checking out this code. its beind a command button and i am have a combo box selecing a query criteria and then pressing the button...
0
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some...
23
by: helm | last post by:
Folks, could anyone advise ... Is there a significant difference in crosstab capabilities in Access and Excel? Using Office XP 2002 ... to produce a crosstab report I developed it in Excel from...
2
by: Aussie Rules | last post by:
Hi, I have a access 2007 database with a cross tab query. Based on the selection critieria the cross tab may contain a different number columns in the result. For example if the query is...
14
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which...
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
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,...
1
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
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...
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.