Computing a Date in a Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a form I want the user to enter a follow up time,
i.e., 1 week, 1 month, 3 months, etc. Based on that
response I want to store an actual date based on today's
date plus whatever was chosen as the follow up timeframe,
1 week would be today + 7. How do I do that?
 
Assuming you can figure out how to convert what the user enters into days,
use the DateAdd function to add that many days to today's date and then
you'll have the desired date.
 
I realize that's what I need to use but I can't get my
formula to work. The user will be selecting from a drop
down with options of 1 week, 1 month, 3 months, 1 year,
for example. So, I tried an IIf with DateAdd using Date
() as today's date. Would you mind sending me a sample
of the statement? THANKS so much.
 
How about something like:

select case cmbTermLength
case "1 week"
EndDate = DateAdd ("ww", 1, StartDate)
case "1 month"
EndDate = DateAdd ("m", 1, StartDate)
case "3 months"
EndDate = DateAdd ("m", 3, StartDate)
case "1 year"
EndDate = DateAdd ("yyyy", 1, StartDate)
end select
 
One way would be to add a field to your table (name it fldDays) that is
holding the data that your combo box uses. Put appropriate values in that
field for each record so that the number is the number of days to be added
when that item is selected. For example, 7 is the value for 1 week, 21 is
the value for 3 weeks, etc.

Then use a multicolumn combo box that uses this as a query (example) for the
row source:
SELECT fldDays, TimeTermField FROM TableName;

For the combo box's properties:
- set the bound column to 1.
- set the column count to 2.
- set the column widths to 0";1'.

This way, when the user selects the term desired (which will show in the
dropdown list), the combo box's value will be the actual number of days to
be used. Thus, you could use the DateAdd function to get the new date from
today's date:
NewDate = DateAdd("d", Me.ComboBoxName.Value, Date())

This won't be an exact method for "one month".

Another option could be to put two fields in the table, where one field is
the abbreviation in DateAdd for the specific term interval (m for month, d
for day, yyyy for year; the other field would be the number. Then you could
have three columns in the combo box query, and use this query as the Row
Source:
SELECT fldDays, fldInterval, TimeTermField FROM TableName;

For the combo box's properties:
- set the bound column to 1.
- set the column count to 3.
- set the column widths to 0";0";1'.

Then, you could use the DateAdd function to get the new date from today's
date:
NewDate = DateAdd(Me.ComboBoxName.Column(1), Me.ComboBoxName.Value,
Date())
 
Back
Top