Results 1 to 8 of 8
  1. #1
    bishmedia is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    44

    Wild Card Issue


    All

    If i have several customers starting with e.g. 'RAN', how would you use a wildcard to count them all, the query below keeps giving me a count rather than a sum??

    =Sum(IIf([Customer]="RAN*",[Quantity],1))

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Don't use = with wildcards, use LIKE

    =Sum(IIf([Customer] LIKE "RAN*",[Quantity],1))
    plus, use DSum to sum over a field in a domain. Your posted expression probably results in 1 for each record? I would have attempted an example expression, but I'm not sure what the table/query name would be, or if the field is [Quantity] or something else.
    Last edited by Micron; 05-19-2018 at 01:49 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    bishmedia is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    44
    Hi
    Ive tried using DSum as below but i get an error
    =DSum(IIf([Customer] Like "RAN*",[Quantity],1))

    'The expression you entered has a function containing the wrong number of arguments'

    Also to COUNT the instances could you substitute DSum with COUNT??

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Domain functions like DSum have three arguments: Field, Table or query, filter condition
    The condition is optional but the other two are required
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Yes, that's what I meant by
    use DSum to sum over a field in a domain
    and not knowing the name of the query or table. I should have posted a link to the function, or an example of it. Not knowing the field or domain name, I opted for the lazy way out.

  6. #6
    bishmedia is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    44
    The query name is 'CycleCountSelection' which opens a report.
    I need to do 2 things....

    Count the number of instances in column 'Customer' beginning with "RAN*" (Textbox1)
    Sum the Column 'Quantity' when the customer begins with "RAN*" (Textbox2)

    So if i had 2 records each with a quantity of 10 - Textbox1 would equal 2 and Textbox2 would equal 20

    Hope that makes sense

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Textbox1: =Sum(IIf([Customer] Like "RAN*", 1, 0))

    or =Count(IIf([Customer] Like "RAN*", 1, Null))

    Textbox2: =Sum(IIf([Customer] Like "RAN*", [Quantity], 0))
    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.

  8. #8
    bishmedia is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    44
    Quote Originally Posted by June7 View Post
    Textbox1: =Sum(IIf([Customer] Like "RAN*", 1, 0))

    or =Count(IIf([Customer] Like "RAN*", 1, Null))

    Textbox2: =Sum(IIf([Customer] Like "RAN*", [Quantity], 0))
    Thankyou June7, this is perfect and has helped me in other areas too.

    Many many thanks

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

Similar Threads

  1. date parameter queries with wild card
    By lwarren in forum Access
    Replies: 3
    Last Post: 03-30-2016, 11:32 AM
  2. drill down and wild card criteria
    By Jen0dorf in forum Access
    Replies: 3
    Last Post: 02-12-2016, 12:12 PM
  3. Criteria from form to query with wild card
    By SteveW in forum Queries
    Replies: 3
    Last Post: 04-01-2011, 07:49 PM
  4. DoCmd.ApplyFilter with wild card
    By cksm4 in forum Programming
    Replies: 3
    Last Post: 10-05-2010, 08:24 AM
  5. Import with a wild card
    By ukgooner in forum Import/Export Data
    Replies: 3
    Last Post: 09-09-2009, 08:08 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