Results 1 to 4 of 4
  1. #1
    dkirtster is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2019
    Posts
    4

    Calculating Expiry Date by adding integer value from a field and a initial date value

    I need a script to calculate an expiry date using an integer and an initial date.
    I have no experience with coding, but I tried the following code copied from a YouTube video;
    "Private Sub date_Post_Change()
    Me.date_Exp = Adddate_Exp(Me.date_Post, Me.txtVal)
    End Sub
    Public Function Adddate_Exp(date_Post As Date, txtVal As Integer) As Date
    Dim rst As Recordset
    Dim db As Database
    Dim date_Exp As Date
    Dim icount As Integer
    End Function"
    I attached a screenshot image of the form showing I am getting a result in Time instead of Date. I need the value in "Validity" to be added to the date in "Post Date" to give the Expiry Date.
    The value in Validity field changes based on the Voucher name selected in the Combobox above it.
    This is the flow;
    - Voucher Name is selected from the combobox
    >voucher name determines the value in the Validity field.
    >the Post Date is chosen
    >the value in the Validity field is added to the Days part of the date in Post Date field to give Expiry date.


    Any help will be greatly appreciated, thanks.Click image for larger version. 

Name:	formImage.jpg 
Views:	11 
Size:	39.7 KB 
ID:	37694
    Last edited by dkirtster; 03-05-2019 at 09:01 AM. Reason: Clarity

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    you dont need coding.
    But set the FORMAT of the field to SHORTDATE.
    set the DEFAULT VALUE of that Expiry date to: =DATEADD("d",12,txtPostDate)

    this says the ex date is 12 days after the Post date.
    you can set "m" for months too.

    no code needed.

  3. #3
    dkirtster is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2019
    Posts
    4
    Thanks so much.
    But, I need the value in the Validity field.
    That value changes based on the Voucher name selected in the COmbobox above it.
    This is the flow;
    - Voucher Name is selected from the combobox
    >voucher name determines the value in the Validity field.
    >the Post Date is chosen
    >the value in the Validity field is added to the Days part of the date in Post Date field to give Expiry date.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Welcome to the forum.

    Try this:

    "Validity" text box Control Source property should be set to "Validity".
    "Post Date" text box Control Source property should be set to "date_Post".
    "Expiry Date" text box is unbound. The Control Source property of the "Expiry Date" text box should be
    Code:
    =IIf(IsNull([Validity]) Or IsNull([Post_Date]),"",DateAdd("d",[Validity],[Post_Date]))

    Because the Expiry Date is calculated, the result should not be saved.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-20-2018, 08:31 AM
  2. Replies: 1
    Last Post: 11-27-2017, 02:02 PM
  3. Replies: 1
    Last Post: 04-29-2016, 04:03 AM
  4. Replies: 6
    Last Post: 03-15-2013, 11:04 AM
  5. Calculating Expiry Date -
    By Jojojo in forum Programming
    Replies: 12
    Last Post: 10-05-2011, 12:05 PM

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