calcluate number of days based on value

Paul Cooke

Registered User.
Local time
Today, 21:44
Joined
Oct 12, 2001
Messages
288
Hi guys could someone point me in the right direction please.

I need to calculate the numbers of days between two dates based on a selection in a combo and also add extra days to it.

e.g. the difference between 01-01-11 and 30-01-11 plus 9

What I have done so far is

Code:
'Case function to calculate numbers of dayes between to periods

Select Case Nz(Me.cboProduct.Column(1), vbNullString)

        'Malarone
        
        Case "Malarone Tablet"
        If Nz(cboProduct, 0) = "Malarone Tablet" Then
        txtDurationOfStay = DateDiff("d", [txtStartDate], [txtEndDate])
        
   End If
   End Select
        
End Function

but is doen't do anything and I have no idea why !

I have about 6 or 7 of these to do which is why I have set up a public function - i am assumming this is the best way to do this? each case will have a different 'plus days ' number

Any help or advice would be gratefully recieved

many thanks
 
I thinnk I may of worked it out !

Code:
If Me.cboProduct.Column(1) = "Malarone Tablet" Then
        Me.txtDurationOfStay = DateDiff("d", Me.txtStartDate, Me.txtEndDate) + 9
        Me.txtTabletsReq = Me.txtDurationOfStay
   End If

End Sub

does anyone see any problems with this code?

thanks
 
Looks like your code should do what you want.
 
Thanks Byron (I could only of worked it out thatnks to your teachings !) I will reply to your email later today
 
follow up to above post

How would I multiply the answer by 2

so if the datedifference is 10 (days) + 9 we get 19 (days) but I need it to be multiplied by 2 (or anther number depending on the case?

thanks for any replies
 
Code:
If Me.cboProduct.Column(1) = "Malarone Tablet" Then
        Me.txtDurationOfStay = ( DateDiff("d", Me.txtStartDate, Me.txtEndDate) + 9) * 2
        Me.txtTabletsReq = Me.txtDurationOfStay
   End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom