?
Solved

Duplicate message

Posted on 2013-11-26
3
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

741 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