Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99

    Creating Your Own Vba Caluculations for a Form

    Hello once again everyone,

    I've developed this calculation first in sql for a persons ReleaseDate base on good behavior; its something we calculate daily in my line of work, However am now learning vba_functions and have just developed a user function in vba of the same calculations works perfectly. The calculations is base on Years, Months and Weeks in jailtime. As is.... I have three defined functions... seperatley but i want them together as one... could I combine these functions as one Singular Function???. because the function Epd Earliest possible date have different variables to years, months and weeks and days,,, there is aslo another argument if the date falls on a Sunday we release the day before dont know how to plug that varialble in either but as is 99% of the time the code give the right answer this is my vba codes:



    Function Epdy(ConDate As Date, intYrs As Integer)
    Dim FD As Date, intDays As Integer
    Dim re As Date, Remmission As Integer
    FD = DateAdd("yyyy", intYrs, ConDate - 1)
    intDays = DateDiff("d", ConDate, FD + 1)
    Remmission = Round(intDays / 3, 0)
    Epdy = (FD - Remmission)


    End Function


    Function Epdm(ConDate As Date, intMth As Integer)
    Dim FD As Date, intDays As Integer
    Dim re As Date, Remmission As Integer
    FD = DateAdd("m", intMth, ConDate - 1)
    intDays = DateDiff("d", ConDate, FD + 1)
    Remmission = intDays / 2
    Epdm = (FD - Remmission)


    End Function

    Function Epdys(ConDate As Date, intdys As Integer)
    Dim FD As Date, intDays As Integer
    Dim re As Date, Remmission As Integer
    FD = DateAdd("d", intDays, ConDate)
    intDays = DateDiff("d", ConDate, FD)


    Remmission = intDays - 30
    Epdys = (FD - Remmission)


    End Function

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    More than likely is doable, but not enough info. I read 2x and can't tell if these are run consecutively, what the inputs might be, what you want out of it and so on. 3 values that you piece together or something? Some data that you're feeding these with and the result you want would be a good start. I'm especially wondering why you can't/don't just get some sort of elapsed time to calculate the release date.

    Would be nice if you also posted your code in code tags (# on forum toolbar) with proper indentation.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Would need some test data and expected results to be able to test the code.

    What are:
    ConDate
    intYrs
    intMth
    intdys?



    Do the function results (Epdy, Epdm, Epdys) get combined into a date?

  4. #4
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99
    HI, Micron.... theres alot of variables to explain... i give it a go again....yes!

    Quote Originally Posted by Micron View Post
    More than likely is doable, but not enough info. I read 2x and can't tell if these are run consecutively, what the inputs might be, what you want out of it and so on. 3 values that you piece together or something? Some data that you're feeding these with and the result you want would be a good start. I'm especially wondering why you can't/don't just get some sort of elapsed time to calculate the release date.

    Would be nice if you also posted your code in code tags (# on forum toolbar) with proper indentation.
    these are 3 three user-defined functions i developed first in sql now vba .it calculates the early release for Prisoners... first one in Years [sentence] second in Months [sentence] third Days [sentence] it must be a date Answer we usually do calculations on paper but in my role as Data Analyst, I've developed a secret way to compute these calculations in Access. now please note.. my overall objective is to have a calculator type Form object where 1. ubound datefield ConvictionDate 2. An interger field could be ubound as well this field represents [years, months and days] and 3. third field bound i.e. =to vba calculation
    ... now there are many variables exg

    [ we say 1year and under divide by 2
    over a year 366 not included divide by 3
    days jailtime u must served 30days
    if date falls on Sunday we release the day b4...a "colonial type thing" lol]..... now all this is dealing with pre-release now look at this small anomaly a judge can say 60 days in the pen as oppose to 2mths but depending on sentence date 2mths jail time could actually be 61 days and same for 3mths... so off by a day is usually trouble.. same as leap years jail time so saying 24 mths could differ from 2 years
    we ususal do these calculations everday ... through ms access am trying to create time efficiency and also have a 5th person the computer brain be checker. We normally have a colleague assign to this job and two others double check to certify correctness
    unbeknownst to them am trying to create an easy routine because i deal with data
    Last edited by Jamesy_007; 12-04-2020 at 05:21 PM.

  5. #5
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99
    Yes ssanfu...Hi thanks for a respone

    Quote Originally Posted by ssanfu View Post
    Would need some test data and expected results to be able to test the code.

    What are:
    ConDate
    intYrs
    intMth
    intdys?

    Do the function results (Epdy, Epdm, Epdys) get combined into a date?
    Please look at the post earlier tried my best to explain thinking it is one thing!... writing for everyone to understand....ah boy the English Language lol

    Again its 3 user defined functions trying to figure out if i can make it one functionality in the Expression builder by dimension it to code hope i said that write
    condate... ConvictonDate
    intyrs.....interger in Years
    intMth.....interger in Months
    intdys.....interger in days
    .....
    and finally yes "function results (Epdy, Epdm, Epdys ) get combined into a date?" YES Epd means Earliest_Possible_Date
    Last edited by Jamesy_007; 12-04-2020 at 05:26 PM.

  6. #6
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99
    Quote Originally Posted by Jamesy_007 View Post
    Yes ssanfu...Hi thanks for a response

    Please look at the post earlier tried my best to explain thinking is one think!... writing for everyone to understand....ah boy the English Language lol

    Again its 3 user defined functions trying to figure out if i can make it one functionality in the Expression builder by dimension it to code hope i said that write
    condate... ConvictonDate
    intyrs.....interger in Years
    intMth.....interger in Months
    intdys.....interger in days
    .....
    and finally yes "function results (Epdy, Epdm, Epdys ) get combined into a date?" YES Epd means Earliest_Possible_Date
    UPDATED Code: jus learned some IF/Else statements

    Function Epdy(ConDate As Date, intYrs As Integer)
    Dim FD As Date, intDays As Integer
    Dim re As Date, Remmission As Integer
    FD = DateAdd("yyyy", intYrs, ConDate - 1)
    intDays = DateDiff("d", ConDate, FD + 1)
    If (intYrs <= 1) Then
    Remmission = Round(intDays / 2, 0)
    Epdy = (FD - Remmission)
    Else
    Remmission = Round(intDays / 3, 0)
    Epdy = (FD - Remmission)
    End If
    End Function


    Function Epdm(ConDate As Date, intMth As Integer)
    Dim FD As Date, intDays As Integer
    Dim re As Date, Remmission As Integer
    FD = DateAdd("m", intMth, ConDate - 1)
    intDays = DateDiff("d", ConDate, FD + 1)
    If (intMth > 12) Then
    Remmission = Round(intDays / 3, 0)
    Epdm = (FD - Remmission)
    Else
    Remmission = Round(intDays / 2, 0)
    Epdm = (FD - Remmission)
    End If
    End Function
    Last edited by Jamesy_007; 12-05-2020 at 09:37 AM.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Looking for something like this?

    Just saw your updated functions, just replace the old ones in the form.

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

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Since you don't seem to want to post code within tags as suggested plus you already have excellent help I'm going to disengage.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99
    WOW....WOW....... Gicu

  10. #10
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99
    Quote Originally Posted by Micron View Post
    Since you don't seem to want to post code within tags as suggested plus you already have excellent help I'm going to disengage.
    No Micron... u don't understand... am totally new to this; were to even ask you how to code with tags not knowledge of all the jargons was never in clerical until recent always worked in operations please forgive me its genuine help am seeking

  11. #11
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99
    Quote Originally Posted by Gicu View Post
    Looking for something like this?

    Just saw your updated functions, just replace the old ones in the form.

    Cheers,
    WOW....WOW....... Gicu...this is the GENERAL IDEA THANKS Bro... haven't properly vet the code yet... but yes this is it..... this is what I was asking you guys for help on... thought my tech language was difficult to understand... am self taught and new to programming and you wouldn't believe I've long pass my prime youthful stage.. it was jus earlier in this year i started using Ms Access. my age in life still learning New things..... a BIG THANKS again for the guidance

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    You're very welcome, post back if you get stuck!
    Good luck with your project!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  13. #13
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Ok, so maybe I'm having a bad day. Or maybe I spend so much time poking around in here and make that request at least once per day it's getting irritating, especially when it's ignored. See the last line in my first post. If you didn't understand it and asked what it meant I'd be happy to elaborate. Shame on me for not doing so right then and there. Sorry!
    So I meant use the # on the forum toolbar and paste your code between the resulting Code and /Code tags. I have to leave off the brackets or I'd create a code window right there.

    Gicu is da man. Probably would give you the shirt off of his back! That's the main reason I bowed out. He seems to be better at seeing the forest whereas I can only see the trees if you know what I mean.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    Jamesy_007 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Location
    Caribbean
    Posts
    99
    Quote Originally Posted by Micron View Post
    Ok, so maybe I'm having a bad day. Or maybe I spend so much time poking around in here and make that request at least once per day it's getting irritating, especially when it's ignored. See the last line in my first post. If you didn't understand it and asked what it meant I'd be happy to elaborate. Shame on me for not doing so right then and there. Sorry!
    So I meant use the # on the forum toolbar and paste your code between the resulting Code and /Code tags. I have to leave off the brackets or I'd create a code window right there.
    .
    Laugh out Loud ... u will not believe how much am learning from you'll... i just fall in LOVE with access and databases i literally go to bed at times 2 ...3 in the morning then for work at 6..Hmmm... and I've just pass my thirties I should've been learning access since early 2000's

  15. #15
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    You got an earlier start with code than me. For many years I was expected to only use queries against linked ODBC tables. I pressed for courses and they reluctantly sent me on one or two long ago, but those didn't get into coding at all. Then my job changed and I slowly managed to show some chops with Access. I'm about 95% self taught in vba, which should give anyone hope.

    You seem to have an interesting job. I sure hope you db doesn't make anyone stay in longer than they have to!

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

Similar Threads

  1. Replies: 7
    Last Post: 05-22-2017, 03:08 PM
  2. Replies: 3
    Last Post: 04-18-2014, 12:20 PM
  3. Replies: 21
    Last Post: 08-05-2013, 06:23 AM
  4. Replies: 3
    Last Post: 04-01-2013, 01:43 PM
  5. Replies: 3
    Last Post: 12-17-2011, 06:05 AM

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