473,385 Members | 1,872 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,385 software developers and data experts.

Prevent Duplicate Order by date

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

10 2634
Rabbit
12,516 Expert Mod 8TB
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
32,556 Expert Mod 16PB
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
nomeepk
12
@rabbit Should i just change these two fields to Indexed (No Duplicates)?
Jan 7 '14 #4
nomeepk
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
5,501 Expert Mod 4TB
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, 1070 views)
Jan 7 '14 #6
NeoPa
32,556 Expert Mod 16PB
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
5,501 Expert Mod 4TB
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
neelsfer
547 512MB
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
5,501 Expert Mod 4TB
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
nomeepk
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

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

Similar topics

3
by: jef3fowler | last post by:
Drawn a blank. Looking to find the last date each client ordered something. The query should show each client and the last order date. 2 tables: Clients and orders. clientID in each. Any...
11
by: ariel81 | last post by:
i have created a function to input data from four textboxes into a table. how do i prevent duplicate records of the same mth/Yr into the table? editing of the data in the table with reference to the...
6
by: Arthur Dent | last post by:
Anyone know, in VB.NET (2005) how to prevent duplicate occurrences of the same event handler on an event? e.g... I have some object which raises an event, and some other class which consumes...
6
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: CODE <?php $c=OCILogon("scott", "tiger",...
0
by: jehrich | last post by:
Hi Everyone, I am a bit of a hobby programmer (read newbie), and I have been searching for a solution to a SQL problem for a recent pet project. I discovered that there are a number of brilliant...
3
by: MBMSOFT | last post by:
Any idea How to prevent from different date/time format on different pc I've heard that I should create my own system time function in VBA which will not depend from the local pc system date/time...
16
mseo
by: mseo | last post by:
I have form based on table with following column name: OrderID PK (autonumber), OrderNo, customer_id OrderNo and coustomer_id are required fields You are allowed to have Same customer,...
4
by: neelsfer | last post by:
Hi This code worked until i changed the "RaceNo" file to text from number format. What brackets or code should i change to make it work? This is to prevent duplicate entries. thx for helping...
3
by: jacc14 | last post by:
Hi When I enter a job number i have set up the following Dim PID As String Dim stLinkCriteria As String Dim rsc As DAO.Recordset Set rsc = Me.RecordsetClone
4
by: waqasi | last post by:
I am allocating a unique number to a patient and want to prevent duplicate entry before update
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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...

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.