Private Sub UserForm_Initialize()
cboChangeType.Value = "Amendment"
cboStockType.Value = "EMU"
txtStockNumber.Value = ""
cboNewStatus.Value = ""
txtShunterMovementFrom.Value = ""
txtShunterMovementTo.Value = ""
txtPoolCodeFrom.Value = ""
txtPoolCodeTo.Value = ""
txtOperatorCodeFrom.Value = ""
txtOperatorCodeTo.Value = ""
txtDepotCodeFrom.Value = ""
txtDepotCodeTo.Value = ""
txtNewOwnershipCode.Value = ""
txtNewLiveryCode.Value = ""
txtNamingAdded.Value = ""
txtNamingRemoved.Value = ""
txtRenumberingFrom.Value = ""
txtRenumberingTo.Value = ""
txtOtherChange.Value = ""
txtDateOfChange.Value = "12/2022"
End Sub
Private Sub cmdAddRecord_Click()
'Used to add new records to the database
Worksheets("Change Records").Activate
Dim lastrow As Long
lastrow = Sheets("Change Records").Range("A" & Rows.Count).End(xlUp).Row
Cells(lastrow + 1, "A").Value = cboChangeType
Cells(lastrow + 1, "B").Value = cboStockType
Cells(lastrow + 1, "C").Value = txtStockNumber
Cells(lastrow + 1, "D").Value = cboNewStatus
Cells(lastrow + 1, "E").Value = txtShunterMovementFrom
Cells(lastrow + 1, "F").Value = txtShunterMovementTo
Cells(lastrow + 1, "G").Value = txtPoolCodeFrom
Cells(lastrow + 1, "H").Value = txtPoolCodeTo
Cells(lastrow + 1, "I").Value = txtOperatorCodeFrom
Cells(lastrow + 1, "J").Value = txtOperatorCodeTo
Cells(lastrow + 1, "K").Value = txtDepotCodeFrom
Cells(lastrow + 1, "L").Value = txtDepotCodeTo
Cells(lastrow + 1, "M").Value = txtNewOwnershipCode
Cells(lastrow + 1, "N").Value = txtNewLiveryCode
Cells(lastrow + 1, "O").Value = txtNamingAdded
Cells(lastrow + 1, "P").Value = txtNamingRemoved
Cells(lastrow + 1, "Q").Value = txtRenumberingFrom
Cells(lastrow + 1, "R").Value = txtRenumberingTo
Cells(lastrow + 1, "S").Value = txtOtherChange
Cells(lastrow + 1, "T").Value = txtDateOfChange
MsgBox cboChangeType & " has been added to the database", 0, "Record Added"
With ActiveSheet
Application.Goto Reference:=.Cells(.Rows.Count, "A").End(xlUp).Offset(-20), Scroll:=True
End With
Call UserForm_Initialize
cboChangeType.SetFocus
End Sub
Private Sub txtStockNumber_AfterUpdate()
'Used for Passenger stock to split the input from 6 digits to 3+3 digits
If Len(txtStockNumber.Text) = 6 And InStr(txtStockNumber.Text, " ") = 0 Then
txtStockNumber.Text = Left(txtStockNumber, 3) & " " & Right(txtStockNumber, 3)
End If
End Sub
Private Sub txtRenumberingFrom_AfterUpdate()
'Used for Passenger stock to split the input from 6 digits to 3+3 digits
If Len(txtRenumberingFrom.Text) = 6 And InStr(txtRenumberingFrom.Text, " ") = 0 Then
txtRenumberingFrom.Text = Left(txtRenumberingFrom, 3) & " " & Right(txtRenumberingFrom, 3)
End If
End Sub
Private Sub txtRenumberingTo_AfterUpdate()
'Used for Passenger stock to split the input from 6 digits to 3+3 digits
If Len(txtRenumberingTo.Text) = 6 And InStr(txtRenumberingTo.Text, " ") = 0 Then
txtRenumberingTo.Text = Left(txtRenumberingTo, 3) & " " & Right(txtRenumberingTo, 3)
End If
End Sub
Private Sub cmdSortRecords()
Dim lngLast As Long
Dim wksAct As Worksheet
Const cstrSort1 As String = "B"
Const cstrSort2 As String = "C"
Const cstrSort3 As String = "T"
Const clngHeader As Long = 3
'change to suit
Set wksAct = Sheets("Change Records")
With wksAct
lngLast = .Cells(.Rows.Count, cstrSort1).End(xlUp).Row
With .Sort.SortFields
.Clear
.Add2 Key:=wksAct.Range(wksAct.Cells(clngHeader, cstrSort1), wksAct.Cells(lngLast, cstrSort1)), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Add2 Key:=wksAct.Range(wksAct.Cells(clngHeader, cstrSort2), wksAct.Cells(lngLast, cstrSort2)), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Add2 Key:=wksAct.Range(wksAct.Cells(clngHeader, cstrSort3), wksAct.Cells(lngLast, cstrSort3)), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
End With
With .Sort
.SetRange wksAct.Range("A" & clngHeader).Resize(lngLast - 2, wksAct.Cells(3, wksAct.Columns.Count).End(xlToLeft).Column)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Set wksAct = Nothing
End Sub
Private Sub cmdClearForm_Click()
Call UserForm_Initialize
End Sub
Private Sub cmdCloseForm_Click()
Unload Me
End Sub