Solved

Duplicate message

Posted on 2013-11-26
3
239 Views
Last Modified: 2013-11-26
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
Comment
Question by:HEMIChallenger
3 Comments
 
LVL 6

Expert Comment

by:zipa72
ID: 39679127
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
 
LVL 18

Accepted Solution

by:
Steven Harris earned 500 total points
ID: 39679144
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
 

Author Closing Comment

by:HEMIChallenger
ID: 39679720
That works perfect. Thank you.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
say, Publisher - saving as Print Ready pdf 3 21
Best Excel  formula for  this scenario 2 36
Office 2016 Temp Files 3 29
Microsoft Office Licensing Question 2 28
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question