textbox tarih hatası

sirkülasyon

Altın Üye
Katılım
10 Temmuz 2012
Mesajlar
2,482
Excel Vers. ve Dili
2021 LTSC TR
Altın Üyelik Bitiş Tarihi
18-06-2026
Kod:
Private Sub TextBox12_Change()
If Len(TextBox12.Text) = 2 Then TextBox12.Text = TextBox12.Text & "."
If Len(TextBox12.Text) = 5 Then TextBox12.Text = TextBox12.Text & "."
If Len(TextBox12.Text) = 10 Then TextBox12.SetFocus
End Sub
düzgün tarih te girilse anlamsız (22.22.2222 gibi) tarihte girilse kabul ediliyor. Bu durumun düzeltilmesini nasıl yapabilirim?
 
Katılım
6 Temmuz 2015
Mesajlar
925
Excel Vers. ve Dili
2003
Merhabalar,

Şöyle deneyebilirsiniz.

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox1) > 10 Or Not IsDate(TextBox1) Then
MsgBox "Hatalı giriş yaptınız"
TextBox1 = ""
Exit Sub
End If

TextBox1 = Format(TextBox1, "dd.mm.yyyy")

If CDate(TextBox1) > "31.12.2020" Or CDate(TextBox1) < "01.01.2020" Then
MsgBox "Tarih aralığı 2020 yılı içinde olmalıdır."
TextBox1 = ""
Exit Sub
End If
End Sub
 
Üst