AW: wenn Datum doppelt TextBox 2,3,4,5,6 deaktivieren
30.06.2016 00:16:47
Christian
Hallo Michael
ups, hast recht. Die Datei kann ich nicht uploaden, ist zu groß, aber den betreffenden Code (nicht von mir).
Option Explicit
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim wks As Worksheet
Dim oCtrl As Control
Dim arrDat As Variant
Dim iRow As Integer, iRowT As Integer, iRowL As Integer, iCol As Integer, iArr As Integer
If ComboBox1.Text = "" Then
MsgBox "Bitte fehlende Eingabe ergänzen"
ComboBox1.SetFocus
Exit Sub
End If
If Not IsComplete Is Nothing Then
IsComplete.SetFocus
MsgBox "Bitte fehlende Eingabe ergänzen"
Exit Sub
End If
arrDat = Array(1, 7, 8)
For iArr = 0 To UBound(arrDat)
Set oCtrl = Controls("TextBox" & arrDat(iArr))
If Not IsDate(oCtrl.Text) Then
If iArr = 0 Then
MsgBox "Bitte ein gültiges Datum eingeben"
With oCtrl
.SetFocus
.SelStart = 0
.SelLength = .TextLength
End With
Exit Sub
Else
If ComboBox1.Text = "Hotelübernachtung" Then
MsgBox "Bitte ein gültiges Datum eingeben"
With oCtrl
.SetFocus
.SelStart = 0
.SelLength = .TextLength
End With
Exit Sub
End If
End If
ElseIf Year(CDate(oCtrl.Text))
Private Function IsComplete() As Control
Dim oCtrl As Control
Dim arr As Variant
Dim iArr As Integer
arr = Array(1, 2, 3, 4, 6, 10)
For iArr = 0 To UBound(arr)
Set oCtrl = Controls("TextBox" & arr(iArr))
If oCtrl = "" Then
Set IsComplete = oCtrl
Exit Function
End If
Next iArr
If ComboBox1.Text = "Tanken" And TextBox9.Text = "" Then
Set IsComplete = TextBox9
ElseIf ComboBox1.Text = "Hotelübernachtung" And TextBox7.Text = "" Then
Set IsComplete = TextBox7
ElseIf ComboBox1.Text = "Hotelübernachtung" And TextBox8.Text = "" Then
Set IsComplete = TextBox8
End If
End Function
Private Sub ComboBox1_Change()
If ComboBox1.Text = "Tanken" Then
TextBox9.Enabled = True
Label10.Enabled = True
Else
TextBox9.Enabled = False
Label10.Enabled = False
End If
If ComboBox1.Text = "Hotelübernachtung" Then
TextBox7.Enabled = True
Label7.Enabled = True
TextBox8.Enabled = True
Label8.Enabled = True
Else
TextBox7.Enabled = False
Label7.Enabled = False
TextBox8.Enabled = False
Label8.Enabled = False
End If
End Sub
Private Sub UserForm_Initialize()
Dim iRow As Integer, iRowL As Integer, iCol As Integer
ComboBox1.List = Worksheets("DATA").Range("TEXTE").CurrentRegion.Value
iRowL = WorksheetFunction.CountA(Worksheets("DATA").Columns(1))
iRow = ActiveCell.Row
If Not IsEmpty(Cells(ActiveCell.Row, 1)) Then
TextBox1.Text = Format(Cells(iRow, 1).Value, "dd.MM.yyyy")
If Not IsEmpty(Cells(iRow, 9)) Then Controls("TextBox7").Text = Format(Cells(iRow, 9). _
Value, "dd.MM.yyyy")
If Not IsEmpty(Cells(iRow, 10)) Then Controls("TextBox8").Text = Format(Cells(iRow, 10). _
Value, "dd.MM.yyyy")
For iCol = 2 To 6
Controls("TextBox" & iCol).Text = Cells(iRow, iCol).Value
Next iCol
ComboBox1.Text = Cells(iRow, 7).Value
TextBox10.Text = Cells(iRow, 15).Text
ElseIf Worksheets("DATA").Range("TEST_MOD").Value = 1 Then
For iRow = 1 To iRowL
Controls(Worksheets("DATA").Cells(iRow, 1).Value).Value = Worksheets("DATA").Cells( _
iRow, 3).Text
Next iRow
End If
End Sub