473,407 Members | 2,326 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,407 software developers and data experts.

Duplicate Prevention & Continue Data Entry

102 64KB
Hello Friends
I am making a database for Drawings Duplication Check. Fields are given below

DRAWING it is Numeric SheetFrom it is Numeric
SheetTo it is Numeric

Suppose Drawing Number is 500 and Sheet From 1 is already entered...... if I try to enter same data it gives me Duplication Message.

But Drawing Number is 500 and Sheet From is 2 ... it again gives me Duplication error and then stuck the cursor. I want it to continue Data Entry and give me Duplication Message only if Drawing Number and Sheet From is SAME. Code is below
*****************************
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     Dim dwgNo, FromPg As String
  3.     Dim stLinkCriteria As String
  4.  
  5.     dwgNo = Me.Drawing.Value
  6.     FromPg = Me.PAGEFROM.Value
  7.  
  8.     If IsNull(Me.Drawing) Then
  9.         MsgBox "Please Enter Drawing Number. This field can not be empty" & vbCrLf & _
  10.             " ", _
  11.             vbCritical, _
  12.             "Canceling Update"
  13.         Me.Drawing.SetFocus
  14.         Cancel = True
  15.     End If
  16.  
  17.     If DCount("[Drawing]", _
  18.         "Drawings", _
  19.         "[Drawing]='" & Me.[Drawing] & "'") > 0 Then
  20.         MsgBox "Alert . *****  This Drawing Number is already Exist" & vbCrLf & _
  21.             " ", _
  22.             vbCritical, _
  23.             "Canceling Update"
  24.       Cancel = True
  25.     End If
  26. End Sub
******************

Thanks in Advance
irsmalik
Mar 20 '19 #1
3 1006
twinnyfo
3,653 Expert Mod 2GB
irsmalik,

Since you have been around for a few threads, you should know by now that we require code tags on your posts. Plesae use these in the future.

Second, I'm going to get on my soap box again, because there is an ongoing trend of DB designers using the default MS naming convention for their controls. Just because MS has failed our community terribly and hasn't allowed us to set default control prefixes doesn't mean that we shouldn't use them.

Advice: It is always highly recommended that you rename the controls on your form to something other than "merely" the underlying field name. Yes, this is a default of MS access, but I think MS has failed here. When you have a text box named Drawing that refers to an underlying field with the same name, when you refer to this field/control, this can be ambiguous for the DB. You always want to be explicit, not vague. So, I would recommend you rename these controls to txtDrawing and txtPAGEFROM. You should also rename your table to tblDrawings, so that you know that you are referring to a Table and not some other object. In the long run, over time, you will appreciate this advice.

Additionally, there is almost never a need to refer to a controls .Value property, as it is the default whenever you refer to it.

Also, as I look at your code, you say that your field values are numeric, but you are referring to it as a string in your code.

Also, reather than using the Form's BeforeUpdate Event, use the Control's Beforeupdate Event.

If I were to clean up your code a bit, this is what we have:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtDrawing_BeforeUpdate(Cancel As Integer)
  2.     Dim dwgNo       As Integer
  3.     Dim FromPg      As Integer
  4.     Dim stLinkCriteria As String
  5.  
  6.     dwgNo = Me.txtDrawing
  7.     FromPg = Me.txtPAGEFROM
  8.  
  9.     If IsNull(Me.txtDrawing) Then
  10.         MsgBox "Please Enter Drawing Number. " & _
  11.             "This field can not be empty", _
  12.             vbCritical, _
  13.             "Canceling Update"
  14.         Me.Undo
  15.     End If
  16.  
  17.     If DCount("[Drawing]", _
  18.         "Drawings", _
  19.         "[Drawing]=" & dwgNo) > 0 Then
  20.         MsgBox "Alert . *****  " & _
  21.             "This Drawing Number already Exists", _
  22.             vbCritical, _
  23.             "Canceling Update"
  24.         Me.Undo
  25.     End If
  26.  
  27. End Sub
Also notice that instead of moving back to the control, we have Me.Undo, which removes the bad value and sets the focus back on that control by default.

Hope this hepps!
Mar 20 '19 #2
irsmalik
102 64KB
Dear twinnyfo

Your Long Advice is appreciated. It was copied from internet.
But I am still looking for Solution.
irsmalik
Mar 20 '19 #3
twinnyfo
3,653 Expert Mod 2GB
I think I offered a solution....

Did my recommendatoin work for you?
Mar 20 '19 #4

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

Similar topics

1
by: Randy | last post by:
I am using Approach 9.8 and have set up a appointment database with the following fields. DATE, TYPEACTION, TIME, WORKER LASTNAME FIRSTNAME I do not want my clerical staff to be able to key in...
5
by: JJ | last post by:
I have a MainForm/subform1/subform2 setup that I thought was working but maybe I just hadn't tested it enough or broke it as I added more features. The database has 2 main tables: Companies and...
6
by: Wayne | last post by:
I am designing a database which needs approximately 50 fields per record. The database user requires data entry to be via a single screen. If I follow good database design practice and split the...
0
by: hrh1818 | last post by:
What type of control would you suggest for use in entering numeric data in a 4 column by n row data entry table. The number of rows n can vary from 3 to 20 and will be detrmined at run time. The...
1
by: Richard | last post by:
Very typical normal data Table One ------ One.OneID (PK) One.Name One.Description One.TwoID (FK) One.ThreeID (FK) ....
8
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables...
8
by: adigga1 | last post by:
I am building a Patient Medical Billing Database and I will be entering duplicate information from time to time, such as, entering a patient that has received a Chest X-ray twice or three time on...
1
by: Data Entry Outsourcing | last post by:
Data Entry plays vital role in every business area. Data Entry is one such aspects of any business that needs to be handled properly for expanding your business. Data Entry is one of the leading...
11
by: rovral | last post by:
I have a data entry form that lists the details of building sales. I know a building can sell more than once so I need to allow duplicate addresses. However, occasionally the same sale will get...
2
by: yaozaah04 | last post by:
Hello, I am working on a data entry form using Microsoft Access 2010 and I am supposed to give the user a separate option to look for a duplicate record. However the duplicate record-checking works...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.