Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,821

    Quote Originally Posted by Ajax View Post
    so filter by the year
    Then the value listed for 2017, which is part of the calculation op posted, won't be included.

  2. #17
    vsssarma is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jan 2019
    Posts
    10
    ArviLaanemets

    The commas should not have been there, they are full stops.

    These two buttons are next to each other; and look similar for a 63 year-young man.

    RGDS

  3. #18
    vsssarma is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jan 2019
    Posts
    10
    Micron

    As more & more data is taken into the Access Database, more months will appear. As of now, data in respect of 13 months has been kept in the database.

    RGDS

  4. #19
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    Then the value listed for 2017, which is part of the calculation op posted, won't be included.
    OK so have a fixed value of '"XXX" and make that the row header. And with regards the missing January data in the calculation, I'm assuming that is down to a poor example, and if it is not, it can easily be excluded with criteria


    However if this is going to go on indefinitely, then a vba solution is probably better since a) the number of columns is limited to 255 (so circa 21 years) and b) the second query would need to be rewritten each month to include the extra month - or use vba

  5. #20
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,821
    Sure, you can "SELECT "yrYear" AS Yr" or whatever, but I think you hit the nail on the head now; eventually the query will max out on fields.
    As for vba, that was offered in post 2, which would negate having to transpose records into fields. However, I thought a function that's used in a query had to be of the nature "Function SomeFunction() As SomeType" and the example isn't.

    This particular thread has been quite muddled what with commas or not, include all values or not, regional settings...
    I played around with my own version, but not sure I see the point of posting it seeing how OP didn't even comment on post 2. I think we're making the assumption OP can use a query that calls such a function but I fear that the next issue would be having the calculation appear on every record because of some query it's used in.

  6. #21
    vsssarma is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jan 2019
    Posts
    10
    VBA or SQL is the right way forward because more & more data will get in.

    RGDS

  7. #22
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    @Micron, declaring function as specific data type is not mandatory, same for the function arguments. They will default to Variant. If type is explicitly declared, better make sure the data passed and function result will be the correct type. Leaving as Variant allows more flexibility although may be best practice to declare type.
    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. #23
    vsssarma is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jan 2019
    Posts
    10
    I think that the VBA solution you offered is the best but I do not know how it is to be taken into the MS Access file. So full code with Syntax is needed. For example, the SQL starts with SELECT.

  9. #24
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Yes, the SQL starts with SELECT. What else would it start with?

    "Take it into MS Access file" by opening VBA editor, creating a general module and a procedure in that module. If you know nothing about writing VBA code, time to learn. Find an online tutorial or buy a book.

    Decide how the date range criteria will be determined. Suggest a form where user can enter values.
    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. #25
    vsssarma is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jan 2019
    Posts
    10
    Thanks. I will try. I did VBA very long time ago. Rgds.

  11. #26
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Hi to all!

    vsssarma,

    This is a user defined VBA function that returns the growth of the desired year.
    Code:
    Function TotalGr(ByVal intYearGr As Integer) As Single
        Dim rs As DAO.Recordset
        Dim sngRes As Single
    
        Set rs = CurrentDb.OpenRecordset( _
                 "SELECT MonthlyGr FROM tblMonthlyGr " _
                 & "WHERE DateGr BETWEEN  DateSerial(" & intYearGr & ",0,17) " _
                 & "AND DateSerial(" & intYearGr & ",12,18);", dbOpenForwardOnly)
    
        With rs
            sngRes = 1
            Do Until .EOF
                sngRes = sngRes * (!MonthlyGr / 100 + 1)
                .MoveNext
            Loop
            .Close
        End With
        Set rs = Nothing
        TotalGr = (sngRes - 1) * 100
    End Function
    And in attachment, you will find a sample database with several ways of use of this function (as ControlSource in a Textbox, as expression in a row of a Union query and as Row Heading in a Crosstab query).

    Regards,
    John
    Attached Files Attached Files

  12. #27
    vsssarma is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Jan 2019
    Posts
    10
    Grateful. Your work is appreciated.

    Can you attempt an SQL also? I am comfortable with MS Access.

    Rgds

    (PS: The percent growths are obtained in an actual forex trading system that I am analyzing. Over 2000% in an year)

  13. #28
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    I am glad I was able to help!

    I don't know if it possible to do loops through records using pure SQL definition and there isn't a SUMPRODUCT() function in SQL aggregate functions. In this case, VBA code it seems to be necessary before you resort to Excel spreadsheets.

    Best regards,
    John

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Similar to a Multiplication Table
    By kraddark in forum Programming
    Replies: 4
    Last Post: 05-25-2012, 11:27 AM
  2. Cumulative totals: Cannot edit a field in recordset
    By Persist in forum Programming
    Replies: 4
    Last Post: 03-11-2012, 06:38 PM
  3. Simply Multiplication on SubForm field using VBA
    By DB2010MN26 in forum Programming
    Replies: 1
    Last Post: 12-10-2011, 01:00 AM
  4. Multiplication of txt box to table field
    By veereshrk in forum Programming
    Replies: 3
    Last Post: 10-01-2011, 05:57 AM
  5. simple multiplication question
    By aaronmarsh632 in forum Access
    Replies: 1
    Last Post: 10-08-2009, 04:51 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