473,651 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form that will create a cross tab query

8 New Member
Hi all,

I would like help on the following problem. I would like to create a form that will have two drop downs (combo or list box), one of which will be a row and the other will be a column. The column values will be a count based on each row value. I've reproduced an example from the Northwind data below. Basically, I would like someone to be able to select one variable (field) and then another to compare and hit SUBMIT and generate a report based on a cross tab query. Any assistance is much appreciated!
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(Products.[Target Level]) AS [CountOfTarget Level]
  2. SELECT Products.[Supplier IDs].[Value], Count(Products.[Target Level]) AS [Total Of Target Level]
  3. FROM Products
  4. GROUP BY Products.[Supplier IDs].[Value]
  5. PIVOT Products.[Target Level];
Jun 11 '09 #1
14 3413
NeoPa
32,568 Recognized Expert Moderator MVP
Where in this example SQL are the two values that you want to select from the ComboBox controls?

I'm afraid you haven't explained the problem very well so it's hard to help.
Jun 11 '09 #2
govind73
8 New Member
I read what I wrote and perhaps I didn't make it too clear. I would like to create a form where I can provide a list of fields. The user will select one field, say X which is how the information is sorted and then can select another field in another drop down, say Y that would be the column headings for a cross tab query. That Y will also be the calculated count for each column and row intersection. Hence:
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(dataset.[Y]) AS CountOfY
  2. SELECT dataset.[X], Count(dataset.[Y]) AS [Total Of Y]
  3. FROM dataset
  4. GROUP BY dataset.[X]
  5. PIVOT dataset.[Y];
I'm very comfortable using Access, but I cannot for the life of me figure out how to produce a list of fields within a form.
Jun 11 '09 #3
govind73
8 New Member
X is one of X1...Xi in a list of fields
Y is one of Y1...Yi in a second list of fields

Depending on what the user chooses, the particular X and Y will then be filled into the SQL, creating a crosstab query. I might note that the SQL in the example is not as important to me as trying to figure out how to insert a field name into X and Y based on input from a form.

Hope I'm making sense :-)
Jun 11 '09 #4
NeoPa
32,568 Recognized Expert Moderator MVP
Starting to (but remember the [ CODE ] tags if you will).

Is the CrossTab query to produced in a VBA string variable, or did you have any other usage for it?

I'll lay out the sort of thing you need for that first and if you need something different just say.

Assuming a form [YourForm] with ComboBox controls [cboX] & [cboY] then :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As string
  2.  
  3. strSQL = "TRANSFORM Count([%Y]) " & _
  4.          "AS [CountOf%Y] " & _
  5.          "SELECT [%X]," & _
  6.          "Count([%Y]) AS [TotalOf%Y] " & _
  7.          "FROM [Dataset] " & _
  8.          "GROUP BY [%X] " & _
  9.          "PIVOT [%Y]"
  10. strSQL = Replace(strSQL, "%X", Me.cboX)
  11. strSQL = Replace(strSQL, "%Y", Me.cboY)
Jun 11 '09 #5
govind73
8 New Member
That is super helpful. The cross tab query has no other use, so using it in VBA will be fine, but...

The only other thing that I am struggling with is getting the values in the combo box into query. So, I have a form called [crosstabs] and two combo boxes called [cboX] and [cboY], so the last two lines ought to be:

Expand|Select|Wrap|Line Numbers
  1. strSQL = Replace(strSQL, "%X", crosstabs.cboX)
  2. strSQL = Replace(strSQL, "%Y", crosstabs.cboY)
right? If so, this gives a run-time error '424', object required.
Jun 11 '09 #6
NeoPa
32,568 Recognized Expert Moderator MVP
If the code is running from within [CrossTabs] then Me.cboX & Me.cboY will work.

Otherwise, assuming that the form is actually open, use Form("CrossTabs ").cboX & Form("CrossTabs ").cboX.

Good luck :)
Jun 11 '09 #7
govind73
8 New Member
If I use Me.cboX & Me.cboY, it doesn't do anything. But, when I use Form("crosstabs ").cboX & Form("crosstabs ").cboX, it produces the error below:

Run-time error '2465':
Microsoft Office Access can't find the field 'crosstabs' referred to in your expression.

This is from a command button. Here is the full code of the command button. Thanks again for your helpful assistance!!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command9_Click()
  2.  
  3. Dim strSQL As String
  4.  
  5. strSQL = "TRANSFORM Count([%Y]) " & _
  6.           "AS [CountOf%Y] " & _
  7.           "SELECT [%X]," & _
  8.           "Count([%Y]) AS [TotalOf%Y] " & _
  9.           "FROM [dataset] " & _
  10.           "GROUP BY [%X] " & _
  11.           "PIVOT [%Y]"
  12. strSQL = Replace(strSQL, "%X", Form("crosstabs").cboX)
  13. strSQL = Replace(strSQL, "%Y", Form("crosstabs").cboY)
  14.  
  15.  
  16. End Sub
Jun 11 '09 #8
NeoPa
32,568 Recognized Expert Moderator MVP
That's purely and simply due to muppetitis. I seem to be suffering from it today :(

The code should have been Forms("CrossTabs").c boX etc.
Jun 11 '09 #9
govind73
8 New Member
Do I need a

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL
type expression to actually execute this. If so, how would I insert it in that code?

Thanks!!
Jun 11 '09 #10

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

Similar topics

3
3956
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my screen. I grabbed this code from the net hoping that I could tweak it for my needs. I'm using MySQL, PHP and IIS and they all are running fine. As the code is, it will display the form, but it won't display my result(s). Any suggestions? Cheers,
25
10218
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
14
3095
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ; ExpenseType Data: 1 ; FOOD 2 ; AIRLINE 3 ; FARE
1
1201
by: hmoulding | last post by:
I'm not talking about a bound control. That's something I've already figured out. I have a form that I use to add and update items in a table. Each item can be of one or more types, so there's a separate table that lists the possible types, and another table that cross connects rows in the item table to the type table. The form has a drop-down list for all possible types, with a button that runs a script to add a row to the cross...
0
1271
by: badboybrown | last post by:
I'm sorry to ask this, but I just can't figure it out and it's probably because it's not possible. I have a Cross-tab query that shows me the sum of items received by brand(Columns) for every month(Rows). It also has a sum at the end of each row to give me a total for the month. I would like to _show_ this on a Form, with a "Year Total" calculated from the month totals.
2
946
by: fstenoughsnoopy | last post by:
I have a customer order database and I need to pull a customers information, ie first name, last name, address, city, state, zip, phone, etc, into the oder table. i don't know how to go about making this work...
5
2589
by: superjacent | last post by:
Hope someone can help. I have a saved parent form containing an unbound sub-form. I set the SourceObject (form) after the Parent Form opens/loads. The sub-form (datasheet view) basically displays the results of a cross-tab query The cross-tab query is created dynamically (in code) as the column headings are subject to change. I therefore have to create a new form (in code) and add the necessary
13
17134
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 launching Excel for data viewing. I'd prefer the user stay in Access. Creating dynamic crosstab queries is pretty simple. The problem is that the column count may shrink or grow depending on the filter.
6
2045
by: Rosie | last post by:
Hi -- I have a main form attached to a table (Invoice header info). When the form loads I use acNewRec to take us to the end of a table, and I get a clean, empty form. The user, who knows their invoice number, enters it into the first textbox on the form. If there's no match on a separate table (a cross referencing process takes place before this) they get a message that the number wasn't found and they get taken back to rest quietly in...
0
8347
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8571
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7294
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4143
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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 we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.