Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating date fields using radio buttons 1

Status
Not open for further replies.

mobile2

Programmer
Dec 19, 2002
38
GB
I have 2 date fields. The first field already has a date entered. I would like to update the second date field automatically once the user has selected one of 4 radio buttons. The radio buttons give the option of 1, 3, 6 or 12 months. Once the user has selected an option it will update the second date field with either 1, 3, 6 or 12 months after the first date field.
 
Hi

Assuming you have arranged your radio buttons into an option group, thus allowing only one of the buttons to be selected (ie on selecting a button, the other are automatically deselected)

In the after update even of the option group (ie the frame control) put

Select Case opgWhichDate
Case 1
i = 3
Case 2
i = 6
...etc
End Select
txtDate2 = DataAdd("m",i,txtDate1) Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
mobile2:

One way to do this is to add the code that follows to the OptionGroup's OnClick property. Assume you've assiged option value 1 to the button for 1 month, option value 2 for 3 months, etc.

Dim datStart as Date

datStart = Me.datebox1name.Value

Select Case Me.OptionGrpName.Value

Case 1
Me.datebox2name.Value = DateSerial(Year(datStart), Month(datStart) + 1, Day(datStart))

Case 2
Me.datebox2name.Value = DateSerial(Year(datStart), Month(datStart) + 3, Day(datStart))

Case 3
Me.datebox2name.Value = DateSerial(Year(datStart), Month(datStart) + 6, Day(datStart))

Case 4
Me.datebox2name.Value = DateSerial(Year(datStart), Month(datStart) + 12, Day(datStart))

End Select

Me.Refresh


There may be other ways, but this should work.

Hope his helps,

Vic

 
Hi!

I would put the radio buttons in an option group and set their option values to 1, 3, 6 and 12 respectively. Then, in the after update event procedure of the frame use the following code:

dtMyFirstDate As Date

dtMyFirstDate = CDate(txtFirstTextBox.Value)
txtSecondTextBox.Value = DateAdd("m", dtMyFirstDate, optDateAdd.Value)

hth
Jeff Bridgham
bridgham@purdue.edu
 
Hi!

I turned the DateAdd function around a little:

txtSecondTextBox.Value = DateAdd("m", optDateAdd.Value, dtMyFirstDate)

Sorry!

Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top