dbTalk Databases Forums  

Prevent duplicate entries in a table through a form

comp.database.ms-access comp.database.ms-access


Discuss Prevent duplicate entries in a table through a form in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jim
 
Posts: n/a

Default Prevent duplicate entries in a table through a form - 04-27-2004 , 01:34 PM






I am designing a data entry form and would like to prevent users from
entering duplicate entries in the underlying table. A record would be
considered a duplicate if it has two fields (date and officename)
equal to a record already in the table. I've created a duplicate
record query to search for records that have matching fields, but
cannot determine how to get the form to check the table using the
query. I've tried tying the query to the AfterUdate Event on the
Officename field (the date is entered automatically when the record is
created), but could not get it to work correctly. Any help is
greatly appreciated. Also, any other suggestions on how to better
resolve this is also appreciated.

Thanks,

Jim

Reply With Quote
  #2  
Old   
Ira Solomon
 
Posts: n/a

Default Re: Prevent duplicate entries in a table through a form - 04-29-2004 , 04:42 PM






There are 2 ways to do this.
The easiest, but not, perhpas, the best, is to make the two fields a
primary key. Or at least a unique index.
You would then get an error message upon saving the record.
But if lots of fields are being entered the user won't know he has a
problem until the end.

The second way is to use a domain aggregate function in the after
update event.

Assume you have a field called x, your date field D and your
officename field O

dim i as integer

i = dcount("x","tablename","d = " & me.date & " and O = '" &
me.officename & "'")

if i >0 then ... ERROR


You might need to put "#" around the date.

Good luck

Ira Solomon

On 27 Apr 2004 11:34:31 -0700, nursingappl (AT) hotmail (DOT) com (Jim) wrote:

Quote:
I am designing a data entry form and would like to prevent users from
entering duplicate entries in the underlying table. A record would be
considered a duplicate if it has two fields (date and officename)
equal to a record already in the table. I've created a duplicate
record query to search for records that have matching fields, but
cannot determine how to get the form to check the table using the
query. I've tried tying the query to the AfterUdate Event on the
Officename field (the date is entered automatically when the record is
created), but could not get it to work correctly. Any help is
greatly appreciated. Also, any other suggestions on how to better
resolve this is also appreciated.

Thanks,

Jim


Reply With Quote
  #3  
Old   
Jim
 
Posts: n/a

Default Re: Prevent duplicate entries in a table through a form - 05-04-2004 , 12:38 PM



Thanks for your reply, Ira. I've incorporated the code that you
suggested, but am still having a couple problems. Because I am not
fluent in VB, could you help me out with a few things...

The Field "X" can be any field that I wish to count, correct? I was
using the index field for the table.

Also, I am getting a debug error relating to the "me.date" entry.
Does that need to be a hard coded date? I want to reference the
current date, which is already listed on the form by the time the user
gets to this field. Does the "me" reference the current form?

Also, you included some single quotes in the code. Are they in the
correct spots? They don't seem to be causing a problem, but I just
want to make sure.

Thanks again,

Jim

Ira Solomon <isolomon (AT) solomonltd (DOT) com> wrote

Quote:
There are 2 ways to do this.
The easiest, but not, perhpas, the best, is to make the two fields a
primary key. Or at least a unique index.
You would then get an error message upon saving the record.
But if lots of fields are being entered the user won't know he has a
problem until the end.

The second way is to use a domain aggregate function in the after
update event.

Assume you have a field called x, your date field D and your
officename field O

dim i as integer

i = dcount("x","tablename","d = " & me.date & " and O = '" &
me.officename & "'")

if i >0 then ... ERROR


You might need to put "#" around the date.

Good luck

Ira Solomon

On 27 Apr 2004 11:34:31 -0700, nursingappl (AT) hotmail (DOT) com (Jim) wrote:

I am designing a data entry form and would like to prevent users from
entering duplicate entries in the underlying table. A record would be
considered a duplicate if it has two fields (date and officename)
equal to a record already in the table. I've created a duplicate
record query to search for records that have matching fields, but
cannot determine how to get the form to check the table using the
query. I've tried tying the query to the AfterUdate Event on the
Officename field (the date is entered automatically when the record is
created), but could not get it to work correctly. Any help is
greatly appreciated. Also, any other suggestions on how to better
resolve this is also appreciated.

Thanks,

Jim

Reply With Quote
  #4  
Old   
Ira Solomon
 
Posts: n/a

Default Re: Prevent duplicate entries in a table through a form - 05-06-2004 , 05:06 PM



Hi:

Yes, X is any field in the table. For Dcount any field will do.

"Me" does refer to the current form. So if your date field is named
"CurrentDate" then you would use: me.currentdate.

Yes, the single quotes are required for strings within strings.

Good luck
Ira Solomon
On 4 May 2004 10:38:54 -0700, nursingappl (AT) hotmail (DOT) com (Jim) wrote:

Quote:
Thanks for your reply, Ira. I've incorporated the code that you
suggested, but am still having a couple problems. Because I am not
fluent in VB, could you help me out with a few things...

The Field "X" can be any field that I wish to count, correct? I was
using the index field for the table.

Also, I am getting a debug error relating to the "me.date" entry.
Does that need to be a hard coded date? I want to reference the
current date, which is already listed on the form by the time the user
gets to this field. Does the "me" reference the current form?

Also, you included some single quotes in the code. Are they in the
correct spots? They don't seem to be causing a problem, but I just
want to make sure.

Thanks again,

Jim

Ira Solomon <isolomon (AT) solomonltd (DOT) com> wrote

There are 2 ways to do this.
The easiest, but not, perhpas, the best, is to make the two fields a
primary key. Or at least a unique index.
You would then get an error message upon saving the record.
But if lots of fields are being entered the user won't know he has a
problem until the end.

The second way is to use a domain aggregate function in the after
update event.

Assume you have a field called x, your date field D and your
officename field O

dim i as integer

i = dcount("x","tablename","d = " & me.date & " and O = '" &
me.officename & "'")

if i >0 then ... ERROR


You might need to put "#" around the date.

Good luck

Ira Solomon

On 27 Apr 2004 11:34:31 -0700, nursingappl (AT) hotmail (DOT) com (Jim) wrote:

I am designing a data entry form and would like to prevent users from
entering duplicate entries in the underlying table. A record would be
considered a duplicate if it has two fields (date and officename)
equal to a record already in the table. I've created a duplicate
record query to search for records that have matching fields, but
cannot determine how to get the form to check the table using the
query. I've tried tying the query to the AfterUdate Event on the
Officename field (the date is entered automatically when the record is
created), but could not get it to work correctly. Any help is
greatly appreciated. Also, any other suggestions on how to better
resolve this is also appreciated.

Thanks,

Jim


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.