Results 1 to 4 of 4
  1. #1
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528

    Date of maturity

    Hello All
    I have a table that contains dates of childhood vaccines, there is a field in the table name (BCG) of type Date, the date of the first dose of the vaccine.
    What I want is.
    Field on the Form calculates the month and two days from the date of the first dose and shows me the date of the next or second dose.

    I have used this code


    = DateAdd ('m', 1, [bcg])
    But show me a month difference does not appear to me days difference
    I want a month and two days

    Thanks in advance

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    try this...put this function into a module.
    the parameter....(time difference)... must be given in seconds...
    usage: ElapsedTimeAsTextRecur (datediff("s",[bcg],date()))

    Code:
    'USAGE:  ElapsedTimeAsTextRecur(655)
    Public Function ElapsedTimeAsTextRecur(ByVal pvSecs, Optional ByVal pvSecBlock)
    'recursive time lapse given seconds
    Dim vTxt
    Dim iNum As Long
    Const kDAY = 86400
    Const kSECpYR = 31536000
    
    
    '60 sec = 1 min             60 sec
    '60 min = 1 hr            3600 sec
    '24 hr = 1 day           86400 sec
    '7 days = 1 week        604800 sec
    '30 days = 1 month     2592000
    '12 months = 1 year = 31536000
    
    
    'YEARS
    If IsMissing(pvSecBlock) Then pvSecBlock = kSECpYR
    iNum = pvSecs \ pvSecBlock
        
        Select Case pvSecBlock
           Case kSECpYR   'yr
              sUnit = "years"
              If iNum > 0 Then
                   vTxt = iNum & " years "
                   pvSecs = pvSecs - (iNum * pvSecBlock)
              End If
              vTxt = vTxt & ElapsedTimeAsTextRecur(pvSecs, 2592000)
              
          Case 2592000    'MO
              sUnit = "months"
              If iNum > 0 Then
                   If iNum > 11 Then iNum = 11
                   vTxt = vTxt & iNum & " months "
                   pvSecs = pvSecs - (iNum * pvSecBlock)
              End If
              vTxt = vTxt & ElapsedTimeAsTextRecur(pvSecs, 604800)
           
           Case 604800     'WEEK
              sUnit = "weeks"
              If iNum > 0 Then
                   If iNum > 3 Then iNum = 3
                   vTxt = vTxt & iNum & " weeks "
                   pvSecs = pvSecs - (iNum * kDAY * 7)
              End If
              vTxt = vTxt & ElapsedTimeAsTextRecur(pvSecs, 86400)
           
           Case kDAY      'day
              sUnit = "days"
              If iNum > 0 Then
                   vTxt = vTxt & iNum & " days "
                   pvSecs = pvSecs - (iNum * kDAY)
              End If
              vTxt = vTxt & ElapsedTimeAsTextRecur(pvSecs, 3600)
           
           Case 3600       'hrs
              sUnit = "hrs"
              If iNum > 23 Then iNum = 23
              If iNum > 0 Then
                   vTxt = vTxt & iNum & " hrs "
                   pvSecs = pvSecs - (iNum * pvSecBlock)
              End If
              vTxt = vTxt & ElapsedTimeAsTextRecur(pvSecs, 60)
           
           Case 60         'min
              sUnit = "mins"
              If iNum > 0 Then
                   vTxt = vTxt & iNum & " mins "
                   pvSecs = pvSecs - (iNum * pvSecBlock)
              End If
              vTxt = vTxt & ElapsedTimeAsTextRecur(pvSecs, 1)
           
           Case Else
              
              sUnit = "secs"
              If pvSecs > 0 Then vTxt = vTxt & pvSecs & " seconds"
        End Select
        
    ElapsedTimeAsTextRecur = vTxt
    End Function

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    This should do the job
    Code:
    Function Vaccination2(FirstShot As Date) As Date
    
        Dim Vaccination1 As Date
       On Error GoTo Vaccination2_Error
    
        Vaccination1 = FirstShot
        Dim shot2 As Date
        shot2 = DateAdd("m", 1, Vaccination1)
        shot2 = DateAdd("d", 2, Vaccination1)
        Vaccination2 = shot2
        'Debug.Print Vaccination2
    
       On Error GoTo 0
       Exit Function
    
    Vaccination2_Error:
    
        MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure Vaccination2 of Module AWF_Related"
    End Function

  4. #4
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Thanks very much orange
    Thanks very much ranman256
    He has worked very well, thank you orange for help me

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

Similar Threads

  1. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  2. Replies: 3
    Last Post: 03-11-2014, 07:32 PM
  3. Replies: 2
    Last Post: 07-09-2013, 06:31 PM
  4. Replies: 5
    Last Post: 12-18-2012, 02:37 PM
  5. Replies: 3
    Last Post: 08-21-2012, 03:05 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