Results 1 to 8 of 8
  1. #1
    Carleton1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3

    Count postal codes that start with K,M,P,L etc

    I am try to create a query or report that will sum all the Canadian Postal Codes in the field [Home_Postal_Code] that start with a different letter. For example. I need to report that 278 postal codes start with a K. I would like to have all this information in one report. I can run a query using the postal code field with the criteria K* and when I run the query it returns all the postal codes and at the bottom of the query it reports how many records it returned. I cannot however add the same field to the query 10 times and change the criteria to P*, L*, M*. So I need an expression that will capture this information.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Tell us about your table.

    Sounds like (air code-- untested)

    Select Left(postalCode),1) as StartingWith, Count(Left(PostalCode,1))
    From YourTable
    Group By Left(postalCode),1)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The Left function extract not needed in the Count() but do need alias name else Access will assign one like Expr1.

    SELECT Left(PostalCode),1) As StartsWith, Count(*) As CountCodes FROM table GROUP BY Left(PostalCode),1);

    Or build a report using Grouping & Sorting features with aggregate calc in footer sections. Do a grouping on the expression that extracts the first character and use Count(*) in textbox in group footer. This will allow display of detail info as well as summary calcs.
    Last edited by June7; 11-08-2013 at 05:00 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Carleton1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3
    Quote Originally Posted by orange View Post
    Tell us about your table.

    Sounds like (air code-- untested)

    Select Left(postalCode),1) as StartingWith, Count(Left(PostalCode,1))
    From YourTable
    Group By Left(postalCode),1)
    I am not that familiar with expressions and other code but have self taught a bit. My table holds biographical information on our applicants. Annually I use this information to produce a recruitment report. I use the postal code field to report how many applicants we get from different areas of Ontario and Canada.

    I was able to use DCOUNT to count the total number of postal codes in the table but when I tried to enter a criteria "[Home_Postal_Code] like K*) I get an error.

    =DCount("[Home_Postal_Code]","Master for Inquiries & Students","[Home_Postal_Code] like K*)

    Any help would be much appreciated.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Try creating a report as June7 suggested.
    Or create a query using this SQL
    Code:
    SELECT Left(PostalCode),1) As StartsWith
    , Count(*) As CountCodes
     FROM table 
    GROUP BY Left(PostalCode),1);

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Text parameters must be delimited with apostrophes: "[Home_Postal_Code] like 'K*')

    Domain aggregate functions can run slow on forms and reports.

    A report using Grouping & Sorting with aggregate calcs in group footer is the better approach.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Carleton1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3
    Thanks for both your responses. I was able to get the DCOUNT function to work once I put in the apostrophes. Would either of you be able to recommend any good sites or other references that could help me learn more about the expression you were speaking of: SELECT Left(PostalCode),1) As StartsWith, Count(*) As CountCodes FROM table GROUP BY Left(PostalCode),1);. I tried to enter this expression in a textbox and received an "enter parameter value" prompt. I think I need a bit more background knowledge before I attempt this. Any resources regarding this would be great. Thanks again June & and Orange.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That expression is an SQL statement. Create a query with Access query builder, switch to SQL View. This will expose the SQL that Access built for you. SQL (Structured Query Language) is the code used to manipulate data in queries. Tables and queries are what forms and reports are based on (RecordSource property).

    More about SQL http://w3schools.com/sql/default.asp
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2013, 12:02 AM
  2. Show Count from different Zip Codes
    By jo15765 in forum Queries
    Replies: 6
    Last Post: 04-15-2013, 12:36 PM
  3. Start a report on week 40 of a week count
    By aspitalnick in forum Reports
    Replies: 8
    Last Post: 11-28-2012, 04:53 PM
  4. Database Design - Physical / Postal Address Issue
    By PeterPeterson in forum Access
    Replies: 3
    Last Post: 09-27-2012, 06:27 AM
  5. Help with Postal-System Database
    By AccessBoy in forum Access
    Replies: 19
    Last Post: 04-07-2010, 07:21 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums