You are on page 1of 1

Private Sub cmdAddProduct_Click()

Dim X As Integer
Dim nextrow As Range
On Error GoTo cmdAddProduct_Click_Error
Set nextrow = Sheet5.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
For X = 1 To 6
If Me.Controls("Product" & X).Value = "" Then
MsgBox "Missing data"
Exit Sub
End If
Next
If WorksheetFunction.CountIf(Sheet5.Range("E:E"), Me.Product4.Value) > 0 Then
MsgBox "This product code already exists"
Exit Sub
End If
If WorksheetFunction.CountIf(Sheet5.Range("L:L"), Me.Product2.Value) = 0 Then
Select Case MsgBox("This is a new category. It will now be added to the category
list.." _
& vbCrLf & "Are you sure that you want to proceed?" _
, vbYesNo Or vbQuestion Or vbDefaultButton1, "Please check this first")
Case vbYes
Case vbNo
Exit Sub
End Select
Sheet5.Cells(Rows.Count, 12).End(xlUp).Offset(1, 0) = Me.Product2.Value
End If
For X = 1 To 6
nextrow = Me.Controls("Product" & X).Value
Set nextrow = nextrow.Offset(0, 1)
Next
'clear
For X = 1 To 6
Me.Controls("Product" & X).Value = ""
Next
Sortit
On Error GoTo 0
Exit Sub
cmdAddProduct_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdAddPr
oduct_Click of Form frmNewProduct"
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub

You might also like