Bunun için tüm fonksiyonları tekrar gözden geçirdim.
Alınan değerde date olan değişken tiplerini variant olarak değiştirip,
gelen değeri isdate() ile kontrol ettim. Sanırım sorun çözüldü.
Aşağıdaki kodları, ilgili modüle komple kopyalayın, kaydedin ve deneyin.
Kod:
Public Function IzinGunu(BasTar As Variant, DonTar As Variant, Donem As Byte) As Integer
Dim SonrakiAyBasi As Date
IzinGunu = 0
If Not IsDate(BasTar) Then Exit Function
If Not IsDate(DonTar) Then Exit Function
If Donem <> 1 And Donem <> 2 Then Donem = 1
If Donem = 1 Then
If Month(BasTar) = Month(DonTar) Then
IzinGunu = DateDiff("d", BasTar, DonTar)
Else
SonrakiAyBasi = DateAdd("m", 1, DateSerial(Year(BasTar), Month(BasTar), 1))
IzinGunu = DateDiff("d", BasTar, SonrakiAyBasi)
End If
Else
If Month(BasTar) = Month(DonTar) Then
IzinGunu = 0
Else
SonrakiAyBasi = DateAdd("m", 1, DateSerial(Year(BasTar), Month(BasTar), 1))
IzinGunu = DateDiff("d", SonrakiAyBasi, DonTar)
End If
End If
End Function
Public Function IzinTarihi_Bas1(BasTar As Variant, DonTar As Variant) As Date
If Not IsDate(BasTar) Then Exit Function
If Not IsDate(DonTar) Then Exit Function
IzinTarihi_Bas1 = BasTar
End Function
Public Function IzinTarihi_Don1(BasTar As Variant, DonTar As Variant) As Date
Dim SonrakiAyBasi As Date
If Not IsDate(BasTar) Then Exit Function
If Not IsDate(DonTar) Then Exit Function
If Month(BasTar) = Month(DonTar) Then
IzinTarihi_Don1 = DonTar
Else
SonrakiAyBasi = DateAdd("m", 1, DateSerial(Year(BasTar), Month(BasTar), 1))
IzinTarihi_Don1 = DateAdd("d", -1, SonrakiAyBasi)
End If
End Function
Public Function IzinTarihi_Bas2(BasTar As Variant, DonTar As Variant) As Date
Dim SonrakiAyBasi As Date
If Not IsDate(BasTar) Then Exit Function
If Not IsDate(DonTar) Then Exit Function
If Month(BasTar) = Month(DonTar) Then
IzinTarihi_Bas2 = 0
Else
IzinTarihi_Bas2 = DateAdd("m", 1, DateSerial(Year(BasTar), Month(BasTar), 1))
End If
End Function
Public Function IzinTarihi_Don2(BasTar As Variant, DonTar As Variant) As Date
Dim SonrakiAyBasi As Date
If Not IsDate(BasTar) Then Exit Function
If Not IsDate(DonTar) Then Exit Function
If Month(BasTar) = Month(DonTar) Then
IzinTarihi_Don2 = 0
Else
IzinTarihi_Don2 = DonTar
End If
End Function