473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Prevent duplicates on Access form with multiple fields to enter serial numbers.

I have an Access form where the user will enter 20 serial numbers in text fields using a bar code reader. How can I check the form to make sure the same serial number hasn't been scanned more than once before the data is saved. Thanks in advance.

Here is the code i've tried so far.

Expand|Select|Wrap|Line Numbers
  1. Dim Ctrl As Control
  2.     For Each Ctrl In Me.Controls
  3.     If Ctrl.Tag = "dcheck" Then
  4.         If Ctrl.Name <> ActiveControl.Name And _
  5.         Ctrl.Text = ActiveControl.Text Then
  6.         MsgBox ActiveControl.Text & " is a duplicate of Box " & Ctrl.Name
  7.         Dups = True
  8.     End If
  9. End If
  10. Next Ctrl
  11.  
Erica
Sep 30 '10 #1
3 2246
MMcCarthy
14,534 Expert Mod 8TB
I think you are on the right track. I'm guessing your problem is in the use of ActiveControl.Name as the focus will move from control to control during the check.

Try this ...


Expand|Select|Wrap|Line Numbers
  1. Dim Ctrl As Control
  2. Dim ctlName As String
  3.  
  4.     ctlName = ActiveControl.Name
  5.     For Each Ctrl In Me.Controls
  6.         If Ctrl.Tag = "dcheck" Then
  7.             If Ctrl.Name <> ctlName And _
  8.                 Ctrl.Text = Control(ctlName).Text Then
  9.                 MsgBox Control(ctlName).Text & " is a duplicate of Box " & Ctrl.Name
  10.                 Dups = True
  11.             End If
  12.         End If
  13.     Next Ctrl
  14.  
Sep 30 '10 #2
ADezii
8,834 Expert 8TB
Why not avoid ActiveControl altogether? After all 20 Serial Numbers are entered into the Form, poll the Text Boxes, then list any Duplication, pin-pointing the Text Boxes involved. After rethinking, this may be a little messy, but only you cab decide whether or not you wish to use this approach. The only problem with this Logic is that Duplicates will be listed twice, as illustrated in the Sample Output, but if you want to take this route, I'm sure that can be corrected.
Expand|Select|Wrap|Line Numbers
  1. Dim ctl_1 As Control
  2. Dim ctl_2 As Control
  3.  
  4. For Each ctl_1 In Me.Controls
  5.   If ctl_1.Tag = "dcheck" And Not IsNull(ctl_1) Then
  6.     For Each ctl_2 In Me.Controls
  7.       If ctl_2.Tag = "dcheck" And Not IsNull(ctl_2) Then
  8.         If ctl_1.Name <> ctl_2.Name And ctl_1 = ctl_2 Then
  9.           Debug.Print ctl_1.Name & " and " & ctl_2.Name & " are Duplicates!"
  10.         End If
  11.       End If
  12.     Next
  13.   End If
  14. Next
Sample OUTPUT (notice duplication):
Expand|Select|Wrap|Line Numbers
  1. Text2 and Text6 are Duplicates!
  2. Text6 and Text2 are Duplicates!
  3. Text11 and Text12 are Duplicates!
  4. Text12 and Text11 are Duplicates!
Sep 30 '10 #3
Thanks for your response. I ended up using the following code that worked.

Expand|Select|Wrap|Line Numbers
  1. Dim Ctrl As Control
  2.     For Each Ctrl In Me.Controls
  3.         If Ctrl.Tag = "dcheck" Then
  4.             If Ctrl.Name <> ActiveControl.Name And _
  5.                 Ctrl.Value = ActiveControl.Value Then
  6.                 MsgBox ActiveControl.Value & " has already been entered." '& Ctrl.Name
  7.                 Dups = 1
  8.             End If
  9.           End If
  10.         Next Ctrl
  11.  
Sep 30 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ccll20022000 | last post by:
Just curious. I am writing a description for a site I want developers to build (mostly in flash) I was wondering if it is possible to prevent pasting into a field Thanks! ccll20022000
3
by: kjaggi | last post by:
I am trying to either write a trigger or a check constraint to prevent duplicates in my table. There are two columns I need to look at for the duplicates and only one combo value for both columns...
2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
3
by: Stewart Allen | last post by:
Hi there I'm trying to find part serial numbers between 2 numbers. The user selects a part number from a combo box and then enters a range of serial numbers into 2 text boxes and the resulting...
6
by: Jack | last post by:
Hi, I have an Access application which need to be converted to asp-sql server application. This Access application uses a single form. This form has got a SS number with names and age. The form...
2
blyxx86
by: blyxx86 | last post by:
Great insight needed!! Good evening everyone.. I've come to a point where I can't even fathom how to go forward. I'm attempting to create a serialized inventory. I don't know where to begin....
4
by: N2Deep | last post by:
I have a table named SUPPORT DATA, I have a field named Serial Number. In the Serial Number field I have many duplicates, and I only want one of each. Sample serials ABB045000MG, JBX05050016 ...
7
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
2
by: abirch | last post by:
Hey. So the problem that I'm running into involves auto-numbering invoice numbers. My boss has 3 tables, 2 of which are only to temporarily store information, but when she goes to create a new...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.