Solved

Duplicate message

Posted on 2013-11-26
3
221 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now