Connecting Tech Pros Worldwide Help | Site Map

How to prevent to enter duplicate record?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 02:04 PM
MP
Guest
 
Posts: n/a
Default How to prevent to enter duplicate record?

I need a code in the Before Update event procedure, which prevents to
enter duplicate record in a form.

I have the main formX, which takes values from the table named tblX and
a subformY, which takes values form the table named tblY. Both forms
are mutually related with a key CustomerID.

I need a code, which makes:
If is field named txtX in formX AND the field named txtY in the
subformY are equal, or entered before, then generate a massage. The
message has to be generated when the field named txtY in the subformY
is already entered.

Thanks for helping me, Mojca


  #2  
Old November 13th, 2005, 02:05 PM
MP
Guest
 
Posts: n/a
Default Re: How to prevent to enter duplicate record?

Example:

If the first filed named txtX = 789/05 - formX And
If the secon field named txtY = 07.09.2005 - subformY, then generate a
massage "The record you have entered is a duplicate".

  #3  
Old November 13th, 2005, 02:05 PM
dkintheuk
Guest
 
Posts: n/a
Default Re: How to prevent to enter duplicate record?

You make no sense, sorry but the example you post seems meaningless to
me, anyone else got it?

Are you saying that you want to make it illegal for the data in afield
in a related table to have the same value as a similar named field in
the parent table?

If so you could code this...

private sub block_txtY()

if me.txtY = [forms].[frmX].[txtX] then
msgbox "That value is not allowed", vbokonly
me.txtY = ""
end if

end sub

  #4  
Old November 13th, 2005, 02:06 PM
MP
Guest
 
Posts: n/a
Default Re: How to prevent to enter duplicate record?

Unfortunately not working.
Next time when I entered the same data in a form:
in the first field txtX = 789/05 - formX And
in the secon field txtY = 07.09.2005 - subformY, then
generate a massage "The record you have entered is a duplicate".

  #5  
Old November 13th, 2005, 02:06 PM
MP
Guest
 
Posts: n/a
Default Re: How to prevent to enter duplicate record?

And SQL for find duplicare record is:
SELECT First(FrmX.TxtX) AS Patient, First(FrmY.TxtY) AS Date,
Count(FrmX.TxtX) AS NumberOFduplicateTxtX, FrmX.TxtX AS FrmX, FrmY.TxtY
AS Dates, Count(FrmY.TxtY) AS NumberOFduplicateTxtY
FROM FrmX INNER JOIN FrmY ON FrmX.ID_Patient = FrmY.ID_Patient
GROUP BY FrmX.TxtX, FrmY.TxtY
HAVING (((Count(FrmX.TxtX))>1) AND ((Count(FrmY.TxtY))>1));

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.