How to avoid duplication (1 Viewer)

Ossama22

Registered User.
Local time
Today, 21:42
Joined
Aug 31, 2018
Messages
52
Hello guys ,
I have a button in a form which i use it to transfer data to appending query ( i mean when i click on my button the data in my form transferred to another form and query) but i face some problems and i hope to find solutions, when i click on this button the data transferred successfully, but if i click on it again its added again , which is wrong , i want to avoid this duplication, is there anyway to lock this button to be one time usage only , in more details when i click it ones the data transferred , if i click it again i dont wanna any action to happen
 

moke123

AWF VIP
Local time
Today, 14:42
Joined
Jan 11, 2013
Messages
3,909
have you tried
Code:
me.YourButtonName.Enabled = false
you could also hide the button by moving focus somewhere else and setting the visible to false.
 

Ossama22

Registered User.
Local time
Today, 21:42
Joined
Aug 31, 2018
Messages
52
This is the vba code for my button , shall i add that to my code
 

Attachments

  • E3A3F1BB-B322-40A0-809E-F17136B5581C.jpg
    E3A3F1BB-B322-40A0-809E-F17136B5581C.jpg
    88.4 KB · Views: 38

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:42
Joined
May 21, 2018
Messages
8,519
Are there any unique fields that you can index? If so you will not be able in append duplicates.
 

isladogs

MVP / VIP
Local time
Today, 19:42
Joined
Jan 14, 2017
Messages
18,208
To solve this, you need to have either a unique index or PK field so you can use an unmatched append query.
For example:
Code:
INSERT INTO TotalSales ( SaleDate, TotalAmount )
SELECT DISTINCT [Forms]![YourFormName].[txt_Date] AS PurchasedDate, [Forms]![YourFormName].[txt_Price] AS ToyPrice
FROM ConcurrentTable LEFT JOIN TotalSales ON ConcurrentTable.PurchasedDate = TotalSales.SaleDate
[B]WHERE (((TotalSales.SaleDate) Is Null[/B]));

The WHERE clause prevents duplication.

You can if necessary create a composite index (with no duplicates allowed) for this purpose. If so, include all those fields with Is Null in the WHERE clause filter criteria
 
Last edited:

irsmalik

Registered User.
Local time
Today, 22:42
Joined
Jan 28, 2015
Messages
88
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
*****************************
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim dwgNo, FromPg As String
Dim stLinkCriteria As String

dwgNo = Me.DRAWING.Value
FromPg = Me.PAGEFROM.Value

If IsNull(Me.DRAWING) Then
MsgBox "Please Enter Drawing Number. This field can not be empty" & vbCrLf & _
" ", _
vbCritical, _
"Canceling Update"
Me.DRAWING.SetFocus
Cancel = True
End If


If DCount("[Drawing]", "Drawings", "[Drawing]='" & Me.[DRAWING] & "'") > 0 Then
MsgBox "Alert . ***** This Drawing Number is already Exist" & vbCrLf & _
" ", _
vbCritical, _
"Canceling Update"

Cancel = True

End If
******************

Thanks in Advance
irsmalik
 

isladogs

MVP / VIP
Local time
Today, 19:42
Joined
Jan 14, 2017
Messages
18,208
Is DrawingNumber your primary key field? If so, you cannot have duplicate values. The solution will be to create another autonumber primary key field instead e.g. DrawingID. Then create a unique index for the 2 fields you do not want duplicated
 

irsmalik

Registered User.
Local time
Today, 22:42
Joined
Jan 28, 2015
Messages
88
Dear Mr Isladogs

Yes, you are right... DrawingNumber is primary key in table and set to NoDuplicate. so what will be the solution.
 

Users who are viewing this thread

Top Bottom