Solved fixed exp date on day and month (1 Viewer)

Akai90

Member
Local time
Today, 23:24
Joined
Feb 8, 2022
Messages
49
hi there,

on my form have fixed exp date "31 december" for year it will +1 year .
below is my current code

C#:
Private Sub TarikhTamat_GotFocus()
TarikhTamat = "31 Disember " & Year(TarikhMohon) + TempohMohon
End Sub

TempohMohon = textbox with number 1 --> 5. 1 equal to 1 year
TarikhMohon =current date
TarikhTamat = exp date with 31 december

so i want do this,

if TarikhMohon 1 january 2021 - 30 june 2021, with tempohmohon 1 year
tarikh tamat will be 31 december 2021

if TarikhMohon 1 july 2021 - 31 dicember 2021, with tempohmohon 1 year
tarikh tamat will be 31 december 2022

hope u understand
thanks
 

June7

AWF VIP
Local time
Today, 07:24
Joined
Mar 9, 2014
Messages
4,450
"31 Disember " & Year(TarikhMohan) + IIf(TempohMohon > 1, TempohMohon, IIf(Month(TarikhMohan) < 7, 0, 1))
 

Akai90

Member
Local time
Today, 23:24
Joined
Feb 8, 2022
Messages
49
"31 Disember " & Year(TarikhMohan) + IIf(TempohMohon > 1, TempohMohon, IIf(Month(TarikhMohan) < 7, 0, 1))
thanks sir it working
 

Akai90

Member
Local time
Today, 23:24
Joined
Feb 8, 2022
Messages
49
"31 Disember " & Year(TarikhMohan) + IIf(TempohMohon > 1, TempohMohon, IIf(Month(TarikhMohan) < 7, 0, 1))
HI,

can u explain this --> IIf(TempohMohon > 1, TempohMohon, IIf(Month(TarikhMohan) < 7, 0, 1)) 0 stand for and 1 stand for

what if tempohmohon 2 year --> 5 year

for 2 year

if TarikhMohon 1 january 2021 - 30 june 2021, with tempohmohon 2 year
tarikh tamat will be 31 december 2022

if TarikhMohon 1 july 2021 - 31 dicember 2021, with tempohmohon 2 year
tarikh tamat will be 31 december 2023

for 3 year

if TarikhMohon 1 january 2021 - 30 june 2021, with tempohmohon 3 year
tarikh tamat will be 31 december 2023

if TarikhMohon 1 july 2021 - 31 dicember 2021, with tempohmohon 3 year
tarikh tamat will be 31 december 2024
 

Akai90

Member
Local time
Today, 23:24
Joined
Feb 8, 2022
Messages
49
solved by using if else

C#:
Private Sub TempohMohon_AfterUpdate()
If TempohMohon = "1" Then
TarikhTamat = "31 Disember " & Year(TarikhMohon) + IIf(TempohMohon > 1, TempohMohon, IIf(Month(TarikhMohon) < 7, 0, 1))
Else
If TempohMohon = "2" Then
TarikhTamat = "31 Disember " & Year(TarikhMohon) + IIf(TempohMohon > 2, TempohMohon, IIf(Month(TarikhMohon) < 7, 1, 2))
Else
If TempohMohon = "3" Then
TarikhTamat = "31 Disember " & Year(TarikhMohon) + IIf(TempohMohon > 3, TempohMohon, IIf(Month(TarikhMohon) < 7, 2, 3))
Else
If TempohMohon = "4" Then
TarikhTamat = "31 Disember " & Year(TarikhMohon) + IIf(TempohMohon > 4, TempohMohon, IIf(Month(TarikhMohon) < 7, 3, 4))
Else
If TempohMohon = "5" Then
TarikhTamat = "31 Disember " & Year(TarikhMohon) + IIf(TempohMohon > 5, TempohMohon, IIf(Month(TarikhMohon) < 7, 4, 5))
End If
End If
End If
End If
End If
End Sub
 

Users who are viewing this thread

Top Bottom