Results 1 to 6 of 6
  1. #1
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    121

    how to run module from query

    I have the following function in a module. Now how do I run it in a query?

    Function GetDays360(TimesheetDate as Date, ReleaseDate as Date)
    GetDays360 = ((Year(ReleaseDate)-Year(TimesheetDate))-1)*360+((12-Month(TimesheetDate))*30)+(30-Day(TimesheetDate))+((Month(ReleaseDate)-1*30)+(Day(ReleaseDate))
    End Function

    I saved this as Mod_GetDays360


    I added it to a query like this:

    Months to Release: GetDays360 ([TimesheetDate,[ReleaseDate])

    The query is just calculating the time between i.e., ReleaseDate 10/31/2022 TimesheetDate 9/6/2019 Result 43086
    what I expect to get is the number of months which is 38

    Not sure where I am going wrong. I am new to functions and modules and vba

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you dont run modules, you run the function (or sub) in the mod.
    make sure its public, PUBLIC FUNCTION

    in the query you put the fctn in a field box:
    GetDays360 ([TimesheetDate],[ReleaseDate])

  3. #3
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    121
    Sample0819 w module.zipSample0819 w module.zipI'm missing something. Please see the Months to Release Field in Query1 and let me know how to make it use the function.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Have a look at the updated file. The GetDays360 would give you days (if you use the correct Release variable instead of ReleaseDate as you had it), not months.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    smg is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Apr 2019
    Posts
    121
    That works, thanks again

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You're welcome!
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. How do I use a MODULE in a Cross-Tab Query?
    By timo1999 in forum Modules
    Replies: 2
    Last Post: 12-13-2014, 04:51 PM
  2. Query..Module..Macro....HELP!!!
    By RIRinkRat in forum Modules
    Replies: 1
    Last Post: 10-17-2012, 07:34 PM
  3. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM
  4. Query/module to open the relationships tab?
    By olazabal in forum Modules
    Replies: 1
    Last Post: 04-20-2012, 03:11 AM
  5. Replies: 4
    Last Post: 05-16-2011, 04:58 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