Adding value to an inputted date
I have a prompt that the user inputs a date. I want to add a number of months to that date for a new field but I'm stuck.
I get Object Required: 'theCureDate' when testing this code:
Dim monthsToAdd
monthsToAdd = Field("CustXPrt_UD.ShelfLife_c")
Dim theCureDate
theCureDate = Format.NamedSubStrings("Cure").Value
Dim theExpDate
If monthsToAdd < 0 Then
Value = "Unlimited"
Else
theExpDate = theCureDate.AddMonths(monthsToAdd)
Value = theExpDate
End If
What is the proper way to alter a user input date?
-
I found out how to do it.
First I had to add the field I was adding, in my case months, as a field on the label template. I moved it off to the side so it was unprinted. Then I set its data type to be integer and gave it a datasource name.
Once it had a name I can use it in the script as an integer. I tried converting it in the script but it didn't work, putting it on the label and setting the type was the trick.
Next there is a function called DateValue that gets a date from an input apparently that I needed to use.
Dim monthsToAdd
monthsToAdd = Format.NamedSubStrings("ShelfLife").Value
Dim theCureDate
theCureDate = DateValue(Format.NamedSubStrings("Cure").Value)
If monthsToAdd < 0 Then
'Return the word unlimited
Value = "Unlimited"
Else
'Calculate expiration date
Value = DateAdd("m", monthsToAdd, theCureDate)
End If0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
1 Kommentar