Değerli Hocalarım @berduş ve @atoykan ın yönlendirmeleri ile Microsoft Access ve Excel eğitimlerime devam ediyorum. Onlar kadar bilgili olmasamda daha önce sorunuza benzer bir araştırma yapmıştım. Excel formlarında giriş maskesi kullanılabilir mi, nasıl uygulanır araştırırken aşağıdaki örnek kodu buldum ve kullandım. Sizin de işinize yaramasını dilerim.
Kod:
Dim NewString, MyString, mask As String
Dim position, pos As Variant
Private Sub TextBox1_Change()
If IsNumeric(Right(TextBox1.Text, 2)) And Len(TextBox1.Text) >= 11 Then
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
Else
position = TextBox1.SelStart
MyString = TextBox1.Text
pos = InStr(1, MyString, "_")
If pos > 0 Then
NewString = Left(MyString, pos - 1)
Else
NewString = MyString
End If
If Len(NewString) < 11 Then
TextBox1.Text = NewString & Right(mask, Len(mask) - Len(NewString))
TextBox1.SelStart = Len(NewString)
End If
End If
If Len(TextBox1.Text) >= 11 Then
TextBox1.Text = Left(TextBox1.Text, 10)
End If
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim strDate As String
strDate = Me.TextBox1
If IsDate(strDate) Then
strDate = Format(CDate(strDate), "DD/MM/YYYY")
MsgBox strDate
Else
MsgBox "Wrong date format"
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
position = TextBox1.SelStart
If KeyCode = 8 Then
TextBox1.Text = mask
End If
End Sub
Private Sub UserForm_Initialize()
TextBox1.SelStart = 0
mask = "__/__/____"
TextBox1.Text = mask
End Sub
Murtaza AF