Re: Laufzeitfehler 1004
30.05.2003 13:16:55
Peter T
die Variable letzte kommt von:letzte = (Sheets("COP-Logbuch").UsedRange.Rows.Count + 1)
und Datum1 ist eine Datumszuweisung (TT.MM.JJ) aus dem UserForm:
Private Sub Datum1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 44, 45: KeyAscii = 46 'aus Komma und Minus Punkt machen
Case 46 'Punkt
Case 48 To 57 'Zahlen von 0 bis 9
Case Else: KeyAscii = 0
End Select
End Sub
Private Sub Datum_pruefen(OK As Boolean)
Dim Tag As String, Monat As String, Jahr As String
OK = False
If Not IsDate(Datum1.Value) Then
MsgBox "Datumseingabe falsch.", 48, "Hinweis"
Datum1.SelStart = 0
Datum1.SelLength = Len(Datum1.Value)
Datum1.SetFocus
Exit Sub
End If
Tag = Left(Datum1.Value, InStr(1, Datum1.Value, ".") - 1)
Monat = Mid(Datum1.Value, InStr(1, Datum1.Value, ".") + 1)
Monat = Mid(Monat, 1, InStr(1, Datum1.Value, ".") - 1)
Jahr = Mid(Datum1.Value, Len(Tag) + Len(Monat) + 3)
If Len(Jahr) < 4 Then Jahr = "2" & String(4 - Len(Jahr) - 1, "0") & Jahr
Select Case CInt(Monat)
Case 1, 3, 5, 7, 8, 10, 12
If CInt(Tag) > 31 Then
MsgBox "Tag falsch.", 48, "Hinweis"
Datum1.Value = Datum1.Value
Datum1.SelStart = 0
Datum1.SelLength = Len(Datum1.Value)
Datum1.SetFocus
Exit Sub
End If
Case 4, 6, 9, 11
If CInt(Tag) > 30 Then
MsgBox "Tag falsch.", 48, "Hinweis"
Datum1.SelStart = 0
Datum1.SelLength = Len(Datum1.Value)
Datum1.SetFocus
Exit Sub
End If
Case 2
If CInt(Jahr) Mod 4 = 0 And (CInt(Jahr) Mod 100 <> 0 Xor CInt(Jahr) Mod 400 = 0) Then
If CInt(Tag) > 29 Then
MsgBox "Tag falsch.", 48, "Hinweis"
Datum1.SelStart = 0
Datum1.SelLength = Len(Datum1.Value)
Datum1.SetFocus
Exit Sub
End If
Else
If CInt(Tag) > 28 Then
MsgBox "Tag falsch.", 48, "Hinweis"
Datum1.SelStart = 0
Datum1.SelLength = Len(Datum1.Value)
Datum1.SetFocus
Exit Sub
End If
End If
End Select
If CInt(Monat) > 12 Then
MsgBox "Monat falsch.", 48, "Hinweis"
Datum1.SelStart = 0
Datum1.SelLength = Len(Datum1.Value)
Datum1.SetFocus
Exit Sub
End If
If CInt(Jahr) < CInt(Year(Date)) Then
MsgBox "Jahr falsch.", 48, "Hinweis"
Datum1.SelStart = 0
Datum1.SelLength = Len(Datum1.Value)
Datum1.SetFocus
Exit Sub
End If
' Datum1.Value = Format(Datum1.Value, "TT.MM.JJJJ")
OK = True
End Sub