Search code examples
excelvbauserform

Populate date based on combobox selection


I have two items in ComboBox1, one is Cardio Only and second is Gym Only.
I want to auto populate Renew Date in TextBox8 based on Combobox1 selection.

e.g.
If I select "CARDIO ONLY" then Next Renew date should be 90days + currentdate or 3 months + current date in TextBox8.
If I select "GYM ONLY" then Next Renew date should be 30days + currentdate or 1 month + currentdate in TextBox8.

(in days)
90 + 22/01/2022 = 22/04/2022
30 + 22/01/2022 = 21/02/2022

(in months)
3 + 22/01/2022 = 22/04/2022
1 + 22/01/2022 = 21/02/2022


Solution

  • Private Sub ComboBox1_Change()
    
       Dim mth As Long
       Select Case Me.ComboBox1.Value
           Case "GYM ONLY"
               mth = 1
           Case "CARDIO ONLY"
               mth = 3
       End Select
       If mth > 0 Then
           Me.TextBox8 = Format(DateAdd("m", mth, Date), "dd/mm/yyyy")
       End If
    
    End Sub