You are on page 1of 1

Private Sub cmdAdd_Click()

Dim iRow As Long


Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

'find first empty row in database


iRow = ws.Cells(Rows.Count, 3) _
.End(xlUp).Offset(1, 0).Row

If WorksheetFunction.CountIf(ws.Range("A2", ws.Cells(iRow - 1, 1)),


Me.textbox1.Value) > 0 Then
MsgBox "Duplicate Code Found", vbCritical
Exit Sub
End If

'check for a part number


If Trim(Me.textbox1.Value) = "" Then
Me.textbox1.SetFocus
MsgBox "Please enter the Code"
Exit Sub
End If

'copy the data to the database


ws.Cells(iRow, 3).Value = Me.textbox1.Value
ws.Cells(iRow, 4).Value = Me.textbox2.Value
ws.Cells(iRow, 5).Value = Me.textbox3.Value
ws.Cells(iRow, 6).Value = Me.textbox4.Value
ws.Cells(iRow, 6).Value = Me.textbox5.Value
ws.Cells(iRow, 6).Value = Me.textbox6.Value

'clear the data


Me.textbox1.Value = ""
Me.textbox2.Value = ""
Me.textbox3.Value = ""
Me.textbox4.Value = ""
Me.textbox5.Value = ""
Me.textbox6.Value = ""

Me.textbox1.SetFocus

End Sub

You might also like