[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Duplicate message

Hello,
When entering data in the Parts fields (PartBox1). Is it possible if anything in colum B16:B300 entered that when you click on the submit button that a error will message If a duplicate part number entry is not allowed close or resubmit a new part number. I attached the excel doc.
DATA-Q28275571-1-.xlsm
0
HEMIChallenger
Asked:
HEMIChallenger
1 Solution
 
Boris PetrovicConsultantCommented:
Hi HEMIChallenger,

In the CommandButton1_Click (SUBMIT button code) first check if there is a value in your PART column, and then do the appropriate action. I would simply show a message and focus the PartBox1, without even leaving the form.
0
 
Steven HarrisPresidentCommented:
You may want to try adding something along the lines of:

Private Sub CommandButton1_Click()
'Check if Part Number is unique
Dim cell As Range
Dim errorcheck As Boolean
Dim answer As String
answer = UserForm1.PartBox1.Value

For Each cell In Range("B16:B300")
    If cell = answer Then errorcheck = True
Next cell

If errorcheck = True Then
    MsgBox "Duplicate Part numbers are not allowed.  Please try again."
Else
       'your code here
End If
End Sub

Open in new window


This should give you something similar to:

Private Sub CommandButton1_Click()
Dim nextrow As Integer

'Check PartBox1 is unique
Dim cell As Range
Dim errorcheck As Boolean
Dim answer As String
answer = UserForm1.PartBox1.Value

For Each cell In Range("B16:B300")
    If cell = answer Then errorcheck = True
Next cell

If errorcheck = True Then
    MsgBox "Duplicate Part numbers are not allowed.  Please try again."
Else
       
'=COUNTA(A:A)+1
nextrow = WorksheetFunction.CountA(Sheets(Range("F2").Value).Range("A:A")) + 1

Sheets(Range("F2").Value).Cells(nextrow + 14, 1) = Date
Sheets(Range("F2").Value).Cells(nextrow + 14, 2) = answer
Sheets(Range("F2").Value).Cells(nextrow + 14, 3) = UserForm1.BuildingBox2.Value
Sheets(Range("F2").Value).Cells(nextrow + 14, 4) = UserForm1.NameBox1.Value
Sheets(Range("F2").Value).Cells(nextrow + 14, 7) = UserForm1.EmployeeBox4.Value
End If
End Sub

Open in new window

0
 
HEMIChallengerAuthor Commented:
That works perfect. Thank you.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now