|
-
Jan 17th, 2000, 11:30 PM
#1
Thread Starter
Lively Member
Hello...
How to prevent the duplicate records.
That's mean when I'm punch in the data to my
table or copy the data from another source to my table, msgbox will prompt the message.
waiting response from you all...
Thanks
-
Jan 18th, 2000, 12:29 PM
#2
Guru
Setup your table to not allow duplicate entries in the field....
You can do this manually by selecting count from table where primarykey = ####. If > 0, then it already exists
It would be more efficient to allow the DBMS to do the validation, but that depends on your DBMS, if you have one.
Tom
-
Jan 18th, 2000, 11:09 PM
#3
Thread Starter
Lively Member
Hello Tom...
I've two tables. Mytable1 and Mytable2.
In Mytable1 I've one primary key name CustID and in Mytable2 CustID is a foreign key.
So how to prevent duplicate records in Mytable2. That's mean when the records have same CustID, same OrderItem and OrderDate, msgbox will prompt that is a duplicate record.
Still waiting answer from you Tom...
Thanks.
-
Jan 19th, 2000, 12:27 PM
#4
Guru
If ALL 3 fields must be the same to determine if it is a duplicate, then query table2 using all 3 conditions. If recordcount > 1, then error, else, insert.
If you just need to check if the foreign key already exists, setup your foreign key field to not allow duplicates
-
Jan 21st, 2000, 11:25 PM
#5
Thread Starter
Lively Member
Hello Tom...
I've been sit over the night to resolved my problem, but I've no clue to do that.
I just get,
Dim db As Database
Dim rs As Recordset
Set db=OpenDatabase("c:\Mydb.mdb")
Set rs=db.OpenRecordset("SELECT * FROM Mytable2")
If rs.RecordCount > 1 Then
MsgBox("You've Enter A Duplicate Record")
End If
But I don't know which part to put that 3 conditions above when CustId, OrderItem and OrderDate is a same record.
Hopefully Tom, you can continue with my code.
still waiting your response.
-
Jan 22nd, 2000, 12:19 PM
#6
Guru
change this:
"SELECT * FROM Mytable2"
to this:
"SELECT * FROM Mytable2 where CustID = " & MyCustIDVariable & " AND OrderItem = " & MyOrderItemVariable & " AND OrderDate = #" & MyOrderDateVariable & "#"
This assumes CustID and OrderItem are numeric fields, and OrderDate is a date field.
You could also use the COUNT sql function, but we won't get into that right now....
Good luck!
Tom
-
Jan 23rd, 2000, 06:09 PM
#7
Thread Starter
Lively Member
Hello Tom...
I don't know with my code, it's doesn't work.
Please you check my code:
Dim db As Database
Dim rs As Recordset
Dim MyCustId As Long
Dim MyOrderItem As Long
Dim MyOrderDate As Date
"SELECT * FROM Mytable2 where CustID = " & MyCustID & " AND OrderItem = " & MyOrderItem & " AND OrderDate = #" & MyOrderDate & "#"
If rs.RecordCount > 1 Then
MsgBox("You've Enter A Duplicate Record")
End If
Where to put this event either in the Form Activate or Form After Update.
still waiting response from you Tom...
-
Jan 23rd, 2000, 11:21 PM
#8
Guru
Are you assigning any values to your variables? you declare MyCustId, MyOrderID, MyOrderDate, but you should be getting values for these from a textbox or grid, etc. If you do not assign values to these, they will be zero (for longs), etc.
If you are assigning values to these variables, make sure that CustID and OrderItem are defined as numeric in your database, and OrderDate is defined as a date field....
-
Jan 25th, 2000, 06:30 PM
#9
Thread Starter
Lively Member
No, I don't assigning any values to my CustID,OrderItem and OrderDate.
Every day I've a lot of order from many CustID. When I'm punch in the record may be it's more than one a same record I've punch in to my table.
Because in Mytable2 CustID is a foreign key
so it's allow a duplicate record.
If a same CustID was ordered a same OrderItem at the same day (OrderDate), this is a duplicate record should I prevent to Mytable2.
Thanks.
-
Jan 26th, 2000, 12:06 PM
#10
Guru
I meant assigning values to the variables, not the fields. Your variables need to have something in them so the query will work
-
Feb 1st, 2000, 12:10 PM
#11
Thread Starter
Lively Member
Hello Tom...
I'm try thinking how to assigning values to the variables but I don't know how to do it.
Still needs your help.
Thanks
-
Feb 1st, 2000, 12:14 PM
#12
Guru
Hi
example of assigning values to variables:
Code:
dim strMyValue as string
strMyValue = "Hello World!"
msgbox strMyValue
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|