Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Prevent duplicates in sub form

Geek News

Prevent duplicates in sub form
Nick 11/24/2008 7:11:01 AM
I am using a sub form that has autoID(Primary KEY), EntDate , Catagoryrec
using radio buttons that range from 1 to 5 and HRTime. I can have the same
date for more than one catagoryrec but want to prevent duplicate
catagoryrec entries of that EntDate. As an example I could not enter two
record entries with EntDate 11/23 with radion button or catagoryrec2
selected. I would like an error message stating that I have entered duplicate
data for this catagory and date and ask if I want to save entry Yes/No.

Re: Prevent duplicates in sub form
"Allen Browne" <AllenBrowne[ at ]SeeSig.Invalid> 11/24/2008 8:23:23 AM
Create a unique index on the combination of EntDate + CatagoryRec.

Steps:

1. Open your table in design view.

2. Open the Indexes box (Toolbar, or View menu.

3. On a blank row below any existing entries, enter a name for the index and
the first field:
EntdateCategoryrec EndDate

4. In the lower pane of the dialog, set Unique to Yes.

5. On the next row of the dialog, leave the index name blank and enter the
2nd field:
CategoryRec
This indicates that the field is part of the same index.

6. Save the table. Access will ask you if you want it to check whether
existing data violates the index; you decide if you want it to do that or
not.

Notes:
=====
a) If the date field has time values as well, it may not work as you expect.

b) Consider whether you also want to set the Required property to yes for
both fields. (Nulls are not unique.)

c) I've suggested the date first, because this will give you an index on the
date.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Nick" <Nick[ at ]discussions.microsoft.com> wrote in message
news:DAB7419C-B04B-46AD-BD49-8482F4204414[ at ]microsoft.com...
[Quoted Text]
>I am using a sub form that has autoID(Primary KEY), EntDate , Catagoryrec
> using radio buttons that range from 1 to 5 and HRTime. I can have the
> same date for more than one catagoryrec but want to prevent duplicate
> catagoryrec entries of that EntDate. As an example I could not enter two
> record entries with EntDate 11/23 with radion button or catagoryrec2
> selected. I would like an error message stating that I have entered
> duplicate
> data for this catagory and date and ask if I want to save entry Yes/No.

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net