When update the record the entries are saved in the columnheaders ^^

xainthowell

New Member
Joined
Mar 3, 2023
Messages
24
Office Version
  1. 2013
Platform
  1. 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.

display form.png


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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Where do you set the value of last_row so that it isn't defaulting to zero + 1?
Do your users complain about getting so many prompts for missing data?
 
Upvote 0
Solution
Where do you set the value of last_row so that it isn't defaulting to zero + 1?
Do your users complain about getting so many prompts for missing data?
thanks for the reminder i forgot to change the declared variable last_row instead of Selected_row. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,914
Messages
6,175,353
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top