Option Explicit
Dim colOptionButtons As Collection
Private Sub UserForm_Initialize()
Set colOptionButtons = New Collection
Dim ctrl As MSForms.Control
Dim ob As clsOptionButton
For Each ctrl In Me.Controls
If LCase$(Left$(ctrl.Name, 3)) = "opt" Or LCase$(Left$(ctrl.Name, 4)) = "stat" Then
Set ob = New clsOptionButton
Set ob.optionButton = ctrl
colOptionButtons.Add ob
End If
Next ctrl
End Sub
'enter date in textbox of 2 days ago
Private Sub BewVorgestern_Click()
Me.dtBewerbung = Date - 2
Me.Bewerbungsportal.SetFocus
End Sub
'enter date in textbox of 1 days ago
Private Sub BewGestern_Click()
Me.dtBewerbung = Date - 1
Me.Bewerbungsportal.SetFocus
End Sub
'enter date in textbox of today
Private Sub BewHeute_Click()
Me.dtBewerbung = Date
Me.Bewerbungsportal.SetFocus
End Sub
'enter date in textbox of 2 days ago
Private Sub UpVorgestern_Click()
Me.dtLetztesUpdate = Date - 2
Me.Kommentar.SetFocus
End Sub
'enter date in textbox of 1 day ago
Private Sub UpGestern_Click()
Me.dtLetztesUpdate = Date - 1
Me.Kommentar.SetFocus
End Sub
'enter date in textbox of today
Private Sub UpHeute_Click()
Me.dtLetztesUpdate = Date
Me.Kommentar.SetFocus
End Sub
'on enter setfocus on next optionbutton-set
Private Sub dtBewerbung_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Me.Bewerbungsportal.SetFocus
End If
End Sub
'on enter set fo us on next textbox
Private Sub dtLetztesUpdate_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Me.Kommentar.SetFocus
End If
End Sub
'activate optionbutton on text input
Private Sub DynButtonText_Change()
Me.DynButton = True
End Sub
'write in public var
Private Sub EditExist_Click()
Hide
GetVal.Show
End Sub
'enter and clear datas, reset public var and exit form
Private Sub EnterExit_Click()
Call EnterData
IsEdit = False
Me.Hide
End Sub
'enter and clear datas, reset public var. ready for new input
Private Sub EnterNew_Click()
Call EnterData
Call ClearData
IsEdit = False
End Sub
Private Sub UserForm_Activate()
'check if a existing row is to be edited or not
If IsEdit = True Then
'Set lrow = ThisWorkbook.Worksheets(1).ListObjects("bewerbungsliste").ListRows(ListVar)
'fill form with existing datas
With ThisWorkbook.Worksheets(1).ListObjects("bewerbungsliste").ListRows(ListVar)
'Reihe 2, Firma
Me.Firma.Value = .Range(2)
'Reihe 3, Ort
Me.Ort.Value = .Range(3)
'Reihe 4, Datum der Bewerbung
Me.dtBewerbung.Value = .Range(4)
'Reihe 5, Bewerbungsportal
If .Range(5).Value = "Bewerbung er Homepage" Then Me.optBewerbungHomepage.Value = True
If .Range(5).Value = "Bewerbung per Telefon" Then Me.optBewerbungTelefon.Value = True
If .Range(5).Value = "Direktbewerbung (E-Mail)" Then Me.optDirekt.Value = True
If .Range(5).Value = "Get-In-Engineering" Then Me.optGetInEngineering.Value = True
If .Range(5).Value = "Indeed" Then Me.optIndeed.Value = True
If .Range(5).Value = "LinkedIn" Then Me.optLinkedIn.Value = True
If .Range(5).Value = "StepStone" Then Me.optStepStone.Value = True
If .Range(5).Value = "Xing" Then Me.optXing.Value = True
'Reihe 6, Status der Bewerbung
If .Range(6).Value = "absage" Then Me.StatAbsage.Value = True
If .Range(6).Value = "zusage" Then Me.StatZusage.Value = True
If .Range(6).Value = "Bewerbungsgespräch" Then Me.StatVG.Value = True
If .Range(6).Value = "warte auf Antwort" Then Me.StatWarte.Value = True
'Reihe 7, Datum vom letzten Update
Me.dtLetztesUpdate.Value = .Range(7)
'Reihe 9, Kommentar
Me.Kommentar.Value = .Range(9)
End With
End If
'proceed
Me.Firma.SetFocus
End Sub
Private Sub EnterData()
'check if existing row is to be edited and set lrow accordingly
If IsEdit = False Then
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)
Dim tbl As ListObject
Set tbl = ws.ListObjects("Bewerbungsliste")
Set lrow = tbl.ListRows.Add
Else
Set lrow = ThisWorkbook.Worksheets(1).ListObjects("bewerbungsliste").ListRows(ListVar)
End If
With lrow
'enter data
'Reihe 2, Firma
.Range(2) = Me.Firma.Value
'Reihe 3, Ort
.Range(3) = Me.Ort.Value
'Reihe 4, Datum
If Me.dtBewerbung = "" Or Not isdate(Me.dtBewerbung.Value) Then
.Range(4) = Date
Else
Dim DatumBewerbung As Date
DatumBewerbung = Me.dtBewerbung.Value
.Range(4) = DatumBewerbung
End If
'Reihe 5, Portal
If Me.optBewerbungHomepage.Value Then .Range(5) = "Bewerbung per Homepage"
If Me.optBewerbungTelefon.Value Then .Range(5) = "Bewerbung per Telefon"
If Me.optDirekt.Value Then .Range(5) = "Direktbewerbung (E-Mail)"
If Me.optGetInEngineering.Value Then .Range(5) = "Get-In-Engineering"
If Me.optIndeed.Value Then .Range(5) = "Indeed"
If Me.optLinkedIn.Value Then .Range(5) = "LinkedIn"
If Me.optStepStone.Value Then .Range(5) = "StepStone"
If Me.optXing.Value Then .Range(5) = "Xing"
'Reihe 6, Status
If Me.StatAbsage.Value Then .Range(6) = "Absage"
If Me.StatZusage.Value Then .Range(6) = "Zusage"
If Me.StatVG.Value Then .Range(6) = "Bewerbungsgespräch"
If Me.StatWarte.Value Then .Range(6) = "Warte auf Antwort"
'Reihe 7, Letztes Update
If isdate(Me.dtLetztesUpdate.Value) Then
Dim DatumUpdate As Date
DatumUpdate = Me.dtLetztesUpdate.Value
.Range(7) = DatumUpdate
End If
'Reihe 8, Tage Seit Bewerbung
.Range(8).NumberFormat = "general"
'Reihe 9, Kommentar
.Range(9) = Me.Kommentar.Value
End With
'reset public var
IsEdit = False
Call ClearData
End Sub
Private Sub ClearData()
Me.Firma.Value = ""
Me.Ort.Value = ""
Me.dtBewerbung.Value = ""
Me.dtLetztesUpdate.Value = ""
Me.Kommentar.Value = ""
Me.optStepStone.Value = True
Me.DynButtonText.Value = ""
Me.StatWarte.Value = True
Me.Firma.SetFocus
IsEdit = False
End Sub