xainthowell
New Member
- Joined
- Mar 3, 2023
- Messages
- 24
- Office Version
- 2013
- Platform
- Windows
When I update the record, the entries are saved in the column headers. Does anyone have an idea where I might have made a mistake? Thanks.
VBA Code:
Private Sub cmdUpdate_Click()
If Me.txtInviID.Value = "" Then
MsgBox "Please select a record to Update"
Exit Sub
End If
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Data")
Dim Selected_Row As Long
Selected_Row = Application.WorksheetFunction.Match(CLng(Me.txtInviID.Value), sh.Range("A:A"), 0)
'Validate if the textbox is empty ---------------------------------------------------------'
If Me.txtVName.Value = "" Then
MsgBox "Please Enter Name of Fishing Vessel", vbCritical
Exit Sub
End If
If Me.txtGT.Value = "" Then
MsgBox "Please Enter Gross Tonnage", vbCritical
Exit Sub
End If
If Me.txtNT.Value = "" Then
MsgBox "Please Enter Net Tonnage", vbCritical
Exit Sub
End If
If Me.txtCO.Value = "" Then
MsgBox "Please Enter Certificate of Ownership", vbCritical
Exit Sub
End If
If Me.txtCVR.Value = "" Then
MsgBox "Please Enter Certificate of Vessel Registry", vbCritical
Exit Sub
End If
If Me.txtMSMC.Value = "" Then
MsgBox "Please Enter Minimum Safe Manning Certificate", vbCritical
Exit Sub
End If
If Me.txtFVSC.Value = "" Then
MsgBox "Please Enter Fishing Vessel Safety Certificate", vbCritical
Exit Sub
End If
If Me.txtCFVGL.Value = "" Then
MsgBox "Please Enter Commercial Fishing Vessel Gear License", vbCritical
Exit Sub
End If
If Me.txtTMC.Value = "" Then
MsgBox "Please Enter Tonnage Measurement Certificate", vbCritical
Exit Sub
End If
If Me.txtSSL.Value = "" Then
MsgBox "Please Enter Ship Station License", vbCritical
Exit Sub
End If
If Me.txtGRB.Value = "" Then
MsgBox "Please Enter Garbage Record Book", vbCritical
Exit Sub
End If
If Me.txtNCaptain.Value = "" Then
MsgBox "Please Enter Captain's Name", vbCritical
Exit Sub
End If
If Me.txtCLicense.Value = "" Then
MsgBox "Please Enter Captain's License", vbCritical
Exit Sub
End If
If Me.txtCLExDate.Value = "" Then
MsgBox "Please Enter Captain's License Expiration Date", vbCritical
Exit Sub
End If
If Me.txtCSIBNo.Value = "" Then
MsgBox "Please Enter Captain's SIB No.", vbCritical
Exit Sub
End If
If Me.txtCSIBExDate.Value = "" Then
MsgBox "Please Enter Captain's SIB Expiration Date", vbCritical
Exit Sub
End If
If Me.txtNMechanic.Value = "" Then
MsgBox "Please Enter Mechanic's Name", vbCritical
Exit Sub
End If
If Me.txtMLicense.Value = "" Then
MsgBox "Please Enter Mechanic's License", vbCritical
Exit Sub
End If
If Me.txtMLExDate.Value = "" Then
MsgBox "Please Enter Mechanic's License Expiration Date", vbCritical
Exit Sub
End If
If Me.txtMSIBNo.Value = "" Then
MsgBox "Please Enter Mechanic's SIB No.", vbCritical
Exit Sub
End If
If Me.txtMSIBExDate.Value = "" Then
MsgBox "Please Enter Mechanic's SIB Expiration Date", vbCritical
Exit Sub
End If
If Me.txtHPort.Value = "" Then
MsgBox "Please Enter the Home Port", vbCritical
Exit Sub
End If
If Me.txtOwner.Value = "" Then
MsgBox "Please Enter the Owner", vbCritical
Exit Sub
End If
If Me.txtContact.Value = "" Then
MsgBox "Please Enter Contact Number", vbCritical
Exit Sub
End If
' Add the input value in the column of the Data sheet ----------------------------'
sh.Range("B" & last_row + 1).Value = Me.txtVName.Value
sh.Range("C" & last_row + 1).Value = Me.txtGT.Value
sh.Range("D" & last_row + 1).Value = Me.txtNT.Value
sh.Range("E" & last_row + 1).Value = Me.txtCO.Value
sh.Range("F" & last_row + 1).Value = Me.txtCVR.Value
sh.Range("G" & last_row + 1).Value = Me.txtMSMC.Value
sh.Range("H" & last_row + 1).Value = Me.txtFVSC.Value
sh.Range("I" & last_row + 1).Value = Me.txtCFVGL.Value
sh.Range("J" & last_row + 1).Value = Me.txtTMC.Value
sh.Range("K" & last_row + 1).Value = Me.txtSSL.Value
sh.Range("L" & last_row + 1).Value = Me.txtGRB.Value
sh.Range("M" & last_row + 1).Value = Me.txtNCaptain.Value
sh.Range("N" & last_row + 1).Value = Me.txtCLicense.Value
sh.Range("O" & last_row + 1).Value = Me.txtCLExDate.Value
sh.Range("P" & last_row + 1).Value = Me.txtCSIBNo.Value
sh.Range("Q" & last_row + 1).Value = Me.txtCSIBExDate.Value
sh.Range("R" & last_row + 1).Value = Me.txtNMechanic.Value
sh.Range("S" & last_row + 1).Value = Me.txtMLicense.Value
sh.Range("T" & last_row + 1).Value = Me.txtMLExDate.Value
sh.Range("U" & last_row + 1).Value = Me.txtMSIBNo.Value
sh.Range("V" & last_row + 1).Value = Me.txtMSIBExDate.Value
sh.Range("W" & last_row + 1).Value = Me.txtHPort.Value
sh.Range("X" & last_row + 1).Value = Me.txtOwner.Value
sh.Range("Y" & last_row + 1).Value = Me.txtContact.Value
ThisWorkbook.Save
MsgBox "The Data Record is Updated", vbInformation
'Record the current Date filed ------------------------------------------'
sh.Range("Z" & Selected_Row).Value = Now
'Clear Data after saving -------------------------------------------------------------------'
Me.txtVName.Value = ""
Me.txtGT.Value = ""
Me.txtNT.Value = ""
Me.txtCO.Value = ""
Me.txtCVR.Value = ""
Me.txtMSMC.Value = ""
Me.txtFVSC.Value = ""
Me.txtCFVGL.Value = ""
Me.txtTMC.Value = ""
Me.txtSSL.Value = ""
Me.txtGRB.Value = ""
Me.txtNCaptain.Value = ""
Me.txtCLicense.Value = ""
Me.txtCLExDate.Value = ""
Me.txtCSIBNo.Value = ""
Me.txtCSIBExDate.Value = ""
Me.txtNMechanic.Value = ""
Me.txtMLicense.Value = ""
Me.txtMLExDate.Value = ""
Me.txtMSIBNo.Value = ""
Me.txtMSIBExDate.Value = ""
Me.txtHPort.Value = ""
Me.txtOwner.Value = ""
Me.txtContact.Value = ""
Me.txtSearch.Value = ""
Me.txtInviID.Value = ""
Call Refresh_Data
End Sub