Page 3 of 3 FirstFirst 123
Results 31 to 40 of 40
  1. #31
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931

    What is the name of the table? Do you want it hard-coded or passed into the function by variable?

    Why would you have the table name in the sql statement twice? Because that is what your last version is doing.

    Do this:

    Set RstOrig = CurrentDb.OpenRecordset("SELECT [FldSales] FROM [Test 2] WHERE [Marketing View Description]='" & strCriteria & "'", dbOpenDynaset)

    Or this:

    Set RstOrig = CurrentDb.OpenRecordset("SELECT [FldSales] FROM [" & RstName & "] WHERE [Marketing View Description]='" & strCriteria & "'", dbOpenDynaset)
    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.

  2. #32
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51
    Here's a screen shot of the error.

  3. #33
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51
    Here's the error.
    Attached Files Attached Files

  4. #34
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51
    Here's the latest DB. I feel so close!!
    Attached Files Attached Files

  5. #35
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I was looking at your error screenshot and noticed your declaration for your Recordset objects ar not of the DAO type.

    Perhaps,
    dim RstOrig as dao.recordset

    and the other recordset maybe a recordset2 type declaration or a recordsetclone of the first recordset. Not sure exactly what you are after though. Didn't comb through the whole thing.

  6. #36
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51
    I want it to pass through as a variable to keep it flexible.

  7. #37
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    1. the field name in the table is FldSum not FldSales so change the code

    2. the second Set RstOrig at the end of the procedure should be (look at the original code from source thread)

    Set RstOrig = Nothing

    3. this line needs to be two lines, do a carriage return after MoveFirst (it is correct in post 23 but not in the posted db)

    RstSorted.MoveFirstxVal = ((RstSorted.RecordCount - 1) * PercentileValue) + 1

    After those edits the code ran correctly.

    4. the query does not need to be an aggregate - GROUP BY not necessary


    Not sure how flexible that allows the procedure to be since field references are hard coded.
    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. #38
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Nice work June and the others too. It seems to correctly return Q1. I believe the OP may be interrested in an aggregate "Sold To Cust" sum to then calculate the quartile. So the totals query may be appropriate.

  9. #39
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The GROUP BY doesn't do anything for the sample data provided. Results are the same except for the blank row because of all the empty records.
    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.

  10. #40
    tennisbuck is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2012
    Posts
    51
    Thanks June7. This is amazing.

    Here's the formula for DMIN and DMAX

    Lowest: DMin("FldSum","Test 2","[Marketing View Description]=" & Chr(34) & [Marketing View Description] & Chr(34))

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using the Nz function (Access 07)
    By jonny3000 in forum Access
    Replies: 5
    Last Post: 11-15-2012, 12:46 PM
  2. dcount function - new to Access VBA
    By jillp in forum Programming
    Replies: 7
    Last Post: 09-20-2012, 06:35 AM
  3. function in access
    By ali zaib in forum Access
    Replies: 3
    Last Post: 01-14-2012, 01:09 PM
  4. Help with Access - IIf Function
    By cs93 in forum Programming
    Replies: 7
    Last Post: 03-19-2011, 11:52 AM
  5. to_char function in Access?
    By Amber_1977 in forum Queries
    Replies: 0
    Last Post: 01-20-2009, 04:45 PM

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