I understand the formula to apply todays date to a cell is =TODAY(), however, I am looking to apply this date to individual records either when a new record is added or an existing record is modified.
I am hoping that there is a simple line of code that I can insert into the appropriate sub-routine so that the date is inserted when each record is added or updated.
Here is my code for adding a new record. The date should be applied to Column L. GThe highlighted line of code
Private Sub cmdAddRecord_Click()
'Used to add new records to the Preserved Locomotives Database
Dim lastrow As Long
Dim LocomotiveNumber As String
StockNumber = txtBritishRailwaysNumber
If Application.WorksheetFunction.CountIf(Sheets("Preserved Steam Locomotives").Range("D3:D1500"), LocomotiveNumber) > 0 Then
MsgBox "Locomotive Number Already Exists", 0, "Duplication Check"
Call UserForm_Initialize
txtLocomotiveClass.SetFocus
Exit Sub
End If
lastrow = Sheets("Preserved Steam Locomotives").Range("A" & Rows.Count).End(xlUp).Row
Cells(lastrow + 1, "A").Value = txtRailwayCompany
Cells(lastrow + 1, "B").Value = txtLocomotiveClass
Cells(lastrow + 1, "C").Value = txtLocomotiveClassName
Cells(lastrow + 1, "D").Value = txtBuildDates
Cells(lastrow + 1, "E").Value = txtBritishRailwaysNumber
Cells(lastrow + 1, "F").Value = txtRailwayCompanyNumber
Cells(lastrow + 1, "G").Value = txtOtherPreviousNumbers
Cells(lastrow + 1, "H").Value = txtLocomotiveName
Cells(lastrow + 1, "I").Value = txtCurrentLocation
Cells(lastrow + 1, "J").Value = DTPicker3
Cells(lastrow + 1, "K").Value = txtAdditionalInformation
Cells(lastrow + 1, "L").Value = TODAY()
MsgBox txtBritishRailwaysNumber & " has been added to the Preserved Steam Locomotive database", 0, "Locomotive Number Added"
Call UserForm_Initialize
txtLocomotiveClass.SetFocus
End Sub
Hopefully there is a simple solution to add a formula to apply the "action" date only when the corresponding record is added or modified once the message box has been clicked "Yes" and this date should not change until the record is subsequently modified.
I am hoping that there is a simple line of code that I can insert into the appropriate sub-routine so that the date is inserted when each record is added or updated.
Here is my code for adding a new record. The date should be applied to Column L. GThe highlighted line of code
Private Sub cmdAddRecord_Click()
'Used to add new records to the Preserved Locomotives Database
Dim lastrow As Long
Dim LocomotiveNumber As String
StockNumber = txtBritishRailwaysNumber
If Application.WorksheetFunction.CountIf(Sheets("Preserved Steam Locomotives").Range("D3:D1500"), LocomotiveNumber) > 0 Then
MsgBox "Locomotive Number Already Exists", 0, "Duplication Check"
Call UserForm_Initialize
txtLocomotiveClass.SetFocus
Exit Sub
End If
lastrow = Sheets("Preserved Steam Locomotives").Range("A" & Rows.Count).End(xlUp).Row
Cells(lastrow + 1, "A").Value = txtRailwayCompany
Cells(lastrow + 1, "B").Value = txtLocomotiveClass
Cells(lastrow + 1, "C").Value = txtLocomotiveClassName
Cells(lastrow + 1, "D").Value = txtBuildDates
Cells(lastrow + 1, "E").Value = txtBritishRailwaysNumber
Cells(lastrow + 1, "F").Value = txtRailwayCompanyNumber
Cells(lastrow + 1, "G").Value = txtOtherPreviousNumbers
Cells(lastrow + 1, "H").Value = txtLocomotiveName
Cells(lastrow + 1, "I").Value = txtCurrentLocation
Cells(lastrow + 1, "J").Value = DTPicker3
Cells(lastrow + 1, "K").Value = txtAdditionalInformation
Cells(lastrow + 1, "L").Value = TODAY()
MsgBox txtBritishRailwaysNumber & " has been added to the Preserved Steam Locomotive database", 0, "Locomotive Number Added"
Call UserForm_Initialize
txtLocomotiveClass.SetFocus
End Sub
Hopefully there is a simple solution to add a formula to apply the "action" date only when the corresponding record is added or modified once the message box has been clicked "Yes" and this date should not change until the record is subsequently modified.