Sorting Subset Within A Query

Nov 24, 2014

How to sort a subset in a query. I have three fields BatchID,Month and Year. The BatchID can have multiple months and years. I would like to order the final sort so as the Batchs appeared in the order of the highest date combination with in each Batch.

The following is the SQL of my first Query which establish's the lowest and highest date in each batch.

Code:
SELECT tblRevOnlySelYear.BatchID, tblRevOnlySelYear.OperatorID, Max([Year] & IIf(Len([Month])=1,0 & [Month],[Month])) AS Expr1FROM tblRevOnlySelYear
GROUP BY tblRevOnlySelYear.BatchID, tblRevOnlySelYear.OperatorID
HAVING (((tblRevOnlySelYear.OperatorID)=1))
ORDER BY Max([Year] & IIf(Len([Month])=1,0 & [Month],[Month]));

The next SQL is the second query which results in the Batchs in the correct order by year but the months are not correct.

Code:
SELECT tblRevOnlySelYear.BatchID, tblRevOnlySelYear.OperatorID, tblRevOnlySelYear.Month, tblRevOnlySelYear.Year, qryRevTest4_1.[1stDate], qryRevTest4_1.LastDateFROM qryRevTest4 AS qryRevTest4_1 INNER JOIN tblRevOnlySelYear ON qryRevTest4_1.BatchID = tblRevOnlySelYear.BatchID
WHERE (((tblRevOnlySelYear.OperatorID)=1))
ORDER BY qryRevTest4_1.LastDate;

View Replies


ADVERTISEMENT

Adding A Subset Table

Nov 4, 2004

I have been writing a stock control database for my small Jewellery Shop and thanks to all the help and encouragement I have received here can see the light at the end of the tunnel - until I reaised a major design error!

My system is based around every product having a unique Product Code in the form ABC1234

AB is a 2 letter code for the Supplier
C is the category (Ring, Bracelet, Pendant etc)
1234 starts at 1 and gets incremented by 1 for each different product

The problem is that I have no current way of recording different sizes for rings with the same Product Code. So when I run a stock level check I may have 3 rings with the code JWR0021 and if my reorder level is set to 2 I would not reorder any of them. The ring may be a top seller in larger sizes but nobody buys them in the smaller sizes, I am sure you can see my problem.

What I want to do is to add another table for ring sizes but still keep the same Product Code. That way I can keep the code as ABC1234 but have A,B,C etc as subset of data for sizes.

What would be my best way of doing this without having to re write everything?

As usual any suggestions will be most welcome.

View 8 Replies View Related

Removing A Subset From A Main Table

Aug 2, 2007

I have 3 parcel tables. Table 1 contains the parcels of the whole county. Table 2 contains open space parcels and table 3 contains preserved farmlands. I would like to remove parcels in tables 2 and 3 from table 1. Tables 2 and 3 are subsets of table 1.

Basically I have these:

Table 1
PIN attribute1 attribute2 .....attribute6
1
2
3
.
.
.
52,000

Table 2
PIN
5
8
9
12
18
335
789
.
.
.
N

Table 3
PIN
41
51
66
3
78
903
1245
.
.
N

Note that tables 2 and 3 only contain PINs
Does anyone have a script for this problem?
I would appreciate your help on this. Thank you.


Jun

View 7 Replies View Related

Forms :: Creating A Search To Populate Subset Of Records

Apr 21, 2014

I have a form that when initially displayed shows all client records in my database with the ability to add new ones through a "Add New" command button. I have another command button called "Search" that displays a second form containing a dozen or so fields to search and filter down on.

When the Search button is pressed, I display search form and enter data in some of the fields for searching. I then click ok and the main form should now display a subset of the records based on the data I entered on the search form.

My dilemma is that the WhereCondition of the docmd.OpenForm doesn't work. The doccmd works to open the form when I don't include the WhereCondition, but the moment I put the WhereCondition in, I get an unknown runtime error (3000).

Here's the code. I've stripped out most of the search fields to target just the one until I can get it working, then I'll add the others back in.

Private Sub cmdSearch_Click()
Dim varWhere As Variant
' Initialize the search string to Null
varWhere = Null
If Not IsNothing(Me.srchLastName) Then
varWhere = "([p_last_nam] LIKE '" & Me.srchLastName & "*')"

[Code] ....

View 5 Replies View Related

Modules & VBA :: Form To Display Subset Of Records In Datasheet Mode?

Feb 3, 2015

I created a form to enter the lookup data and build the SQL string to create a recordset in VBA that is a subset of the original data. Using the Form wizard I created a form that displays ALL of the records in that original table (actually a QUERY). What I want to do is open this second form but have it reference the recordset I built in VBA.

View 1 Replies View Related

Sorting A Table, Apply The Sorting To A Form

Mar 10, 2006

Hi all.
I've created a database which contains information about stores. I want to have the forms automaticly sorted by the department number.
I've tried to sort the table by department, but when I try to add a department, the sorting doesn't seem to affect the form at all.

Lets say I have department 1,2,3,6,7,8 in the form, and I add department 4, it will be the last post in the form. I want it to be the fourth, and so on..

I'd apreciate some help with this :) Thanks

Here's the database (http://www.access-programmers.co.uk/forums/attachment.php?attachmentid=12934&stc=1&d=1142018915&PHPSESSID=f730b7f11f6983965698faeacbe5a1ee)

View 5 Replies View Related

Forms :: Create Search Form That Returns Subset Of Other Form Pages?

Sep 25, 2013

I've built a PostgreSQL database for some ecology data and am trying to use MS Access 2010 to make a front-end for it.

I've created a form to display site data; it includes such fields as site ID, site name, county, state, landscape, etc. (There are more, but if I can get the idea down with a couple of these, I should be good to handle the rest). One can click through the form and see 14 pages of site details, which is fine because there are 14 sites.

What I want to do now is make a search form in which one can enter values for site ID, site name, county, etc, and somehow get the pages of the display form that match those values. It's not terribly important to me how that output looks - whether it's a list of matches that allows for clicking on a match and showing just one page of the display form, or whether it's a filtered subset of the display form pages that one still clicks through to view them all.

if there is code to write, where do I type it? Do I start my search form by making a form with the search fields as values, or is there some other way? How do I make those search fields into search boxes rather than display boxes?

View 14 Replies View Related

Help With Sorting A Query?

Aug 9, 2007

I have a job database where I sort jobs by upcoming, inactive, closed and active. Each has a corresponding number 1-4 respectively. The main table I update the jobs in is the JOB TABLE. I print a weekly report for our weekly meeting but I only want the active jobs in the report. My question is: how do I perform a sort function in the query, so I will have only the active jobs in the database table show in the query? Thanks in advance! If more info is needed I wil post additonal.

View 4 Replies View Related

Sorting In A Query

Feb 1, 2007

I'd like to sort in my query - used to populate a combo box - first by name, and then by ID.
Is there a way to force Access to sort in a particular order? It seems like it starts sorting with the first field that's to be sorted, but I want it to start with field 2 and then sort by field 1.

View 2 Replies View Related

Sorting A Query

Feb 6, 2008

I am fairly new at relying heavily on Access for my programming. Problem: I have a telephone database with call detail for every call. I only want specific records, which I am pulling by selecting sort (in query design mode) for that particular field. I need to sort like you would in Excel (Column A first, Column B second, and etc). Can someone help direct me in the right path as to how I need to run a mulitple sort? Your help is much appreciated.

View 1 Replies View Related

Sorting Further From A Duplicates Query

May 13, 2005

I have a Duplicates Query that extract the following information from my Table

Name Surname DOB Joined

The query then extracts info such as...

Bill Smith 25:12:70 1999
Bill Smith 25:12:70 2005

Most of the time the 'Joined' field has the same year. But I need to find the ones where the year differs but the rest of the information is exactly the same. Because there is 15000 odd records to check, I thought that there would be a quicker way to check.

Could someone please assist me with this query if it is possible?

Thank you in advance.

View 1 Replies View Related

Sorting Crosstab Query

Jul 12, 2005

I have a crosstab query where my column headings are the names of the months based on invoice dates.
what i currently have:
Month: MonthName(Month([AnnualIncome]![InvoiceDate]))
so this spits out April May and June in the column headings.
The problem is that it is sorting it alphabetically, not by the numerical value - so my column headings are coming out as april, june, then may. (I assume once I have july that will come in between april and june.)

Any help would be REALLY appreciated.

Thanks in advance.

View 4 Replies View Related

Sorting Records In A Query

Nov 9, 2005

I am having a problem sorting records in a query. I have about 5, 000 entries in a table and when I build my query based on certain fields, the numbers in certain columns are not in order although I use the sorting feature. ( e.g.) I have 5 columns with numbering data contained in the columns, and I have it set up to sort in ascending order, which it did, but I noticed that the Volume # column sorts the Volume numbers differently (see example below):

V. 1
V. 10
V. 11
V. 12
then it goes back to
V. 2
V. 3
V. 4
V. 5
V. 6
V. 7
V. 8
V. 9

It looks like it sorts anything with a 1 first then the rest later. How do I fix this?

Thanks.

View 3 Replies View Related

Sorting Query Results

Apr 28, 2006

Hi

I have a problem sorting some query data and I wonder if someone could help point me in the right direction.

I have a query with two columns, in the first column is a number (either 6 or 7) and the second is the name of a business. Eg

Column 1 Column 2
6 Pizzas & Co
6 Pizzas & Co
7 Pizzas & Co
6 IPM Ltd
7 IPM Ltd
6 Computer Sales Ltd
6 Computer Sales Ltd
6 Computer Sales Ltd
7 Computer Sales Ltd
7 Computer Sales Ltd
7 Computer Sales Ltd
7 Computer Sales Ltd
7 Computer Sales Ltd

And I want to produce some another query so that the output which looks like:

Column 1 Column 2 (6's) Column 3 (7's)
Pizzas & Co 2 1
IPM Ltd 1 1
Computer Sales Ltd 3 5

So for each company name, I am essentially doing a frequency count for all the 6's and 7's.

I think this must be relatively easy to do, but I am getting it wrapped around my head!

Many Thanks,
Lee

View 2 Replies View Related

Sorting Query By Date & Employee Name

Apr 3, 2007

I created a query which at first was simply to run a query which asks you for a drivers name, however we have decided that now we want to sort by the employee name as well as by a specified date range. I originaly had it set up to select the driver name with this in the criteria field in the Driver Name column:

[Enter Driver Name]

Then I tried to enter the following in to the criteria field in the date column:

Between [Enter Start Date: (Format MM-DD-YY)] And [Enter End Date: (Format MM-DD-YY]


However when I run the query it asks me for the date about 4 times, and then it goes to a blank report. I am sure I am not doing this properly somehow, anyone care to help out?

View 1 Replies View Related

Queries :: Sorting A Field Within A Query?

Feb 5, 2014

I have a query that pulls info from a table. One of my fields is frequency and in that field i have weekly, annually, daily, etc.

How can I make the query sort starting at the daily one and move out to annually?

View 2 Replies View Related

Queries :: Sorting A Query In Unconventional Way?

Aug 1, 2015

I want to sort the results of a query as follows.

The query returns 4 fields
ID, Field1, Field2, Field3

For the first 500 rows I want to sort by Field1 with the remaining rows sorted by Field3.

I can identify the first 500 rows bi ID being less than 501.

I've done something similar where I've displayed a value of a field in a different order by coding something like

ORDER BY Iif([field3]=9, 0.5, [field3])

which sorts the 9's first followed by the rest in ascending order but can't work out what to do here.

View 14 Replies View Related

Sorting Of Query In Subform Doesn't Happen

Nov 6, 2006

Hi,

I have a query for a subform which is displayed in datasheet mode (see attachment). I've created a form based on a query and used it as a subform.
The "casenumbers" per clients are displayed from 1 and upwards, I would like to have them sorted Descending. So in the query I sorted them that way. When I run the query they are displayed in descending order. When I open the subform based on that query however it is not. I can sort descending anyway by clicking the column on which I want to sort and do it that way, but that becomes bothersome and it doesn't need to be that way.

Record source is ok:
SELECT KlantNAW.ClientNumber, CaseInfoTable.Casenumber, CaseInfoTable.DateInitialCall, CaseInfoTable.DateCaseCreation, CaseInfoTable.CaseAccepted, CaseInfoTable.[1stAppointmentDate], CaseInfoTable.DateCaseClosed, CaseInfoTable.About1 FROM KlantNAW INNER JOIN CaseInfoTable ON KlantNAW.ClientNumber=CaseInfoTable.ClientNumber;

Order by:
Casenumber DESC

I thought, well, lets create a new form based on the query to see if that changes anything, maybe I've changed something I shouldn't have.

But nope, same result.

How can make the form sort descending in datasheet mode?

View 1 Replies View Related

Reports :: Sorting By Date In Query For A Report

Jul 27, 2014

I have a query where I ORDER BY ClientId, MatterId and Transdate. The result of the query is correct. All of the transdates are in ASC order within the Matter.

When I run the report for a MatterId the relative transactions are not sorted on transdate

Can there be something in the report that could be effecting the order of the transactions.

View 3 Replies View Related

Reports :: How To Combine Queries Into A Summary Query Of Sorting

Mar 21, 2013

i intially, I wish to have attendance stats for 3 groups of people over 2 days in a report

i have the two queries for the raw data, but wish to combine into a report that will ultimately become a "dashboard" report for half a dozen queries., and can only get one or the other to work do i need to combine the queries into a summary query of sorts?

View 1 Replies View Related

Sorting Table / Query - Ordering Numeric Values

Dec 30, 2013

I currently have records that end with a letter and 2 numbers. For example, A1, A2, ... , A10, A11. When I try to sort my table/query by these values, A10 & A11 come before A2. It seems that it is sorting by the first digit shown. Is there any way to fix this quickly within table/query properties so that this can be displayed in proper numeric order?

View 7 Replies View Related

Queries :: Complex Query Sorting And Summing Amounts Breakdown

Jan 28, 2015

I have a shell of my database in the below link for reference. I am trying to create a query for a report that will allow me to track charges and payments per client. Each charge has a ChargeID and each payment has a PaymentID. Multiple payments can be applied to one charge so the same ChargeID can show up multiple times with a different PaymentID. Payments that are catagorized as Third Party Payments will have not only a PaymentID, but a TPPaymentID.

What I need to do in the query and final report is track the total charges (even though the ChargeID may show up multiple times, I only want the charge itself to be calculated once and the charge to only be listed once for each client) and track the total payments as well as sum the total payments for each charge for each client.

View 9 Replies View Related

Forms :: Sorting Fields - Syntax Error (Missing Operator) In Query Expression

Sep 16, 2013

I have created a form based on a query. The funny thing is when I tried to sort fields on the form, the following message box pops up:

Syntax Error (Missing Operator) In (Field Name)

I just did the exact same thing several weeks ago, and that first form could sort fields normally. The only difference between the first one and this is that this second query was based on several tables, while the first was based on a single table, although I doubt that is where the problem is.

I forgot to add that I could sort fields where the field name doesn't have spaces in it. For example, the field name "Customer ID" triggers the syntax error, while the field "S/N", "Company", etc. can be sorted like normal.

View 7 Replies View Related

Sorting?

Jun 14, 2007

Hi Everyone,

Could anyone tell me how I sort a field so it sorts by the surname, not the first name? It's one field with 2 names seperated by a space, i.e. George Michael.

Many thanks for any help.

Essex

View 5 Replies View Related

Sorting Out By Dob

Jan 1, 2008

I am doing a database containing names, dates of birth, dates of death etc of my ancestors. Does anyone know the best way of displaying it so I can sort them out by age of death? For example, I want to see someone for example who died aged 70 years and 6 months to be a place above someone who died aged 70 years and 4 months.

View 1 Replies View Related

Sorting

Jun 26, 2007

In Quebec there are a lot of place names beginning with "Saint-" or "Sainte-".

When I do an ascending sort on the table itself, these type of names don't seem to follow the expected pattern.

For the names Sainte-Marthe, Sainte-Thérèse, Saint-Ephrem, Saint-Eulalie I should see this order:

Saint-Ephrem, Saint-Eulalie, Sainte-Marthe, Sainte-Thérèse.

Instead, I get Sainte-Marthe, Saint-Ephrem, Sainte-Thérèse, Saint-Eulalie.

The names are spelled exactly as I have them in the table with hyphens and diacritic marks.

Any ideas why there seems to be a problem sorting "Saint-" from "Sainte-?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved