jadown 0 Newbie Poster

I built a form called PO Log that contains input text boxes that the user can enter the different iputs that will add an existing row to the worksheet called PO_log. I have the add function working perfectly. But I want to add a function to the form that if the record/data already exist using the PO number as an identifier, to udate the existing record/data rather than adding a completely new row of record/data. Here is the code I have below for the adding function.

Private Sub cmdAdd_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PO_log")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
  .End(xlUp).Offset(1, 0).Row

'check for a part number
If Trim(Me.txtVendor.Value) = "" Then
  Me.txtVendor.SetFocus
  MsgBox "Please enter a Order Info"
  Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtVendor.Value
ws.Cells(iRow, 2).Value = Me.txtPONumber.Value
ws.Cells(iRow, 3).Value = Me.txtPurReqDate.Value
ws.Cells(iRow, 4).Value = Me.txtRFQSent.Value
ws.Cells(iRow, 5).Value = Me.txtSentToVen.Value
ws.Cells(iRow, 6).Value = Me.txtDateOfPo.Value
ws.Cells(iRow, 7).Value = Me.txtOrderConf.Value
ws.Cells(iRow, 8).Value = Me.txtAmt.Value

'clear the data
Me.txtVendor.Value = ""
Me.txtPONumber.Value = ""
Me.txtPurReqDate.Value = ""
Me.txtRFQSent.Value = ""
Me.txtSentToVen.Value = ""
Me.txtDateOfPo.Value = ""
Me.txtOrderConf.Value = ""
Me.txtAmt.Value = ""
Me.txtVendor.SetFocus

End Sub


Private Sub cmdClose_Click()
    Unload Me
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.