By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

Prevent Duplicate Order by date

P: 12
Hi,

i need some help here and i m not a vba user but i do use basic macros.
I was to achieve something like this;

field one: ID (Primary key)
Field two; Name
Field three: date
and i got a little subform with these. as some kind of order sheet.

i want it to notify me for Duplicate Name but on a single date. when i enter address in it.
Let me try and explain it again.

One customer cant have more than one orders in a day. even if he makes a repeat purchase, it should notify that today we already got his another order. So i can simply leave the name as it is, but put a child record under the previous order.

but ignore any order which are not with the current date.

Hope that explains.

an Advance thanks.
Jan 7 '14 #1

✓ answered by zmbd

nomeepk:
Not exactly what rabbit is after, what he is suggesting is a composite-indexed key. Because you have not indicated which version of Access you are using, I'll give you the ACC2010 instructions:
Open the table you wish to have the composite index on in desgin view.
A context ribbon for "Table Tools" should be open
"Show/Hide" group
"Indexes"

Once selected, the "Indexes:___" where ___ = table name dialog will open... for simplicty, let's call this the Indexes Table.
If you have a primary key, you will have one entry in the table... "PrimaryKey"
Now look at the two fields you want in the index, in this case say [order_date] and [customer_id]

In the Indexes Table, under the heading [Index Name] make a new entry, let's call it "idx_dailyorders"
under the heading [Field Name] same row as idx_dailyorders, select the first field.
Now on the next row, leave [Index Name] BLANK; in the [Field Name] select the second field.
Now go back and select the index name
You will have a section at the bottom of the indexes table where you can set a few properties, in this case, Primary (if you already have a primary then = NO (I advise against composit keys for primary keys for most uses - that is a subject of much debate) Unique = Yes (obvious - No?) Ignore Nulls = No

And there you have it



You can also do this via SQL in the query editor, however, you have to use SQL, not the standard editor view - and this is not for the faint-of-heart: Create or modify tables or indexes by using a data-definition query

Share this Question
Share on Google+
10 Replies


Rabbit
Expert Mod 10K+
P: 12,366
There's no need for any code. Put a unique index on your name and date fields. That will prevent any entry with a duplicate name / date combination.
Jan 7 '14 #2

NeoPa
Expert Mod 15k+
P: 31,494
What you describe confuses me. If he cannot make another order the same day, how can a child record be put under the previous order?

Be that as it may, I suggest your first step is to look at the design of your table. A unique index that includes both those fields should be put in place. After that, it won't be possible to enter the same data twice. Check out Datebase Normalisation And Table Structures.

When you have a fundamentally sensible design, then you can consider if anything else is even required and, if so , what that is.
Jan 7 '14 #3

P: 12
@rabbit Should i just change these two fields to Indexed (No Duplicates)?
Jan 7 '14 #4

P: 12
@Neopa
Let me try to explain what i want to achieve:
I would always dispatch orders in the evening before closing.
so

You are a customer and You bought an item in the morning.

so i got your name and date and item (in subform)
(The order is not yet dispatched and its in my record)

Later before dispatch you will get one more item.

I already got your Name and today's date
but i will just put another item in your order so at the end it will be one order of two items.

The problem is:

I want it to notify me only if:
You the customer already have an order in Today's date. not in any old date.
Jan 7 '14 #5

zmbd
Expert Mod 5K+
P: 5,397
nomeepk:
Not exactly what rabbit is after, what he is suggesting is a composite-indexed key. Because you have not indicated which version of Access you are using, I'll give you the ACC2010 instructions:
Open the table you wish to have the composite index on in desgin view.
A context ribbon for "Table Tools" should be open
"Show/Hide" group
"Indexes"

Once selected, the "Indexes:___" where ___ = table name dialog will open... for simplicty, let's call this the Indexes Table.
If you have a primary key, you will have one entry in the table... "PrimaryKey"
Now look at the two fields you want in the index, in this case say [order_date] and [customer_id]

In the Indexes Table, under the heading [Index Name] make a new entry, let's call it "idx_dailyorders"
under the heading [Field Name] same row as idx_dailyorders, select the first field.
Now on the next row, leave [Index Name] BLANK; in the [Field Name] select the second field.
Now go back and select the index name
You will have a section at the bottom of the indexes table where you can set a few properties, in this case, Primary (if you already have a primary then = NO (I advise against composit keys for primary keys for most uses - that is a subject of much debate) Unique = Yes (obvious - No?) Ignore Nulls = No

And there you have it



You can also do this via SQL in the query editor, however, you have to use SQL, not the standard editor view - and this is not for the faint-of-heart: Create or modify tables or indexes by using a data-definition query
Attached Images
File Type: jpg BytesThread_953990_compositeindex_v02.JPG (42.0 KB, 616 views)
Jan 7 '14 #6

NeoPa
Expert Mod 15k+
P: 31,494
That makes more sense. I appreciate better what you're asking for. The answer stays the same, but it helps to understand the question anyway :-)

Z has given a very full answer to your question about Rabbit's suggestion. I was planning to myself, but he's already done a better job than I would have - albeit with a PrimaryKey that appears to be Primary = No (Giggles).
Jan 8 '14 #7

zmbd
Expert Mod 5K+
P: 5,397
Now go back and select the index name
Ah... but what you see is not the [Index Name]= "PrimaryKey" properties (^.^) - instead, I have selected the [Index Name]= "idx_DailyOrders" element; thus, you see the propeties for that key in the image.

If I had selected the element [Index Name]= "PrimaryKey" then you would have seen: Primary Key = Yes, Unique = Yes, and Ignore Nulls = No.

I should have drawn the orange indicators in the picture - for some reason they didn't come thru... arrrgh, (\./) .

(I'll fix that... stomp stomp stomp... where's that orange pen... KIDS!!! WHERE'D YOU PUT MY ORANGE BOX!!! Growl - ROAR - FLAMES (chuckle...) )
Jan 8 '14 #8

100+
P: 547
Hope i am not missing something, but this sounds risky to me to to use the surname and date.What happens if a different Mr Jones arrives?
Rather use some unique number or ID linked to this specific person, as well as the date.
Jan 8 '14 #9

zmbd
Expert Mod 5K+
P: 5,397
neelsfer
I certainly agree, notice in my example I use a field named "Customer_ID"
I should have explained that in my post at the time, thank you for bringing that back to point!
Jan 8 '14 #10

P: 12
@Zmbd Thank you so much for you help. yes the problem solved.
and sorry for replying late. last night i actually tried and changed this unique to Yes. and it worked. then i didnt have network so could reply.

Thanks to you All. it really helped me and achieved the required result.
Jan 8 '14 #11

Post your reply

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