How to assign a variable in code

azzurri

Registered User.
Local time
Today, 23:20
Joined
Feb 27, 2002
Messages
25
I have the following line in the event procedure:

If Me.Text67 = 30 + n Then
[Text131] = 1 + (n / 30)
End if

Me.Text67 is function for no of days for a range of period which can be any number that is 30days(1 month)+ n (variable that represent no of days)

Me.Text131 is a function to convert the no of days to decimalized value i.e if Me.Text67=45 days (30+n where n=15),then [Text131]=1+(n/30) that is 1+(15/30)=1.5

How do I put this in code?
 
Dim Text1 as Integer

Text1 = Me.Text67 (Where text67 is the total number of days)

Me.Text131 = (Text1/30)

'Text131 needs to be a text box, data type double.

This is very bad way to go about it. the number of days in a month varies, so using 30 just isn't right. If you enter two date values in the fields, Start Date and an End Date, you can use the DateDiff() function to calculate a more accruate Month + Days.

Something like...

Dim startDate as Date
Dim endDate as Date
firstDayOfMonth as Date
lastDayOfMonth as Date
NoOfDays = Integer
DaysOfMonth = Integer
ExtraDays = Integer

startDate = Me.StartDate
endDate = Me.EndDate
firstDayOfMonth = Me.FirstDay
lastDayOfMonth = Me.LastDay

NoOfDays = DateDiff("d", startDate, endDate)

DaysOfMonth = DateDiff("d", FirstDayOfMonth, LastDayOfMonth)

ExtraDays = (NoOfDays - DaysOfMonth)

Me.Output = "1 Month " & ExtraDays & " Extra days"

Hope this makes sense
 

Users who are viewing this thread

Back
Top Bottom