Print Page | Close Window

Help With Detecting Duplicate Entries

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=9867
Printed Date: 31 March 2026 at 6:23pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Help With Detecting Duplicate Entries
Posted By: redk
Subject: Help With Detecting Duplicate Entries
Date Posted: 16 February 2004 at 1:59pm

Hi there,

Im trying to find the correct code that will take my variable (txtcomments) and check it with what is already in my access database field called 'Team'.

If it cant find it already - it adds it to database
If it does find it already - it wont add & redirects

I already have the 'add to database' part and it works fine - can someone PLEASE help me with the duplicate entry check code? Ive searched the net and cant find anything suitable yet. How do i get it to check whats already there and compare it, then act accordingly?

Here is my page so far:-
-----------------------------------------------
<% If Request.Form("txtcomments") = "" then %>
<% Response.Redirect("notext.htm") %>
<%End If%>

<%
'Dimension variables
Dim AO_GB_Connect   
Dim rsAddComments      
Dim SQL_String        &n bsp;    

Set AO_GB_Connect = Server.CreateObject("ADODB.Connection")
AO_GB_Connect.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("table.mdb")
Set rsAddComments = Server.CreateObject("ADODB.Recordset")
SQL_String= "SELECT * FROM List"

rsAddComments.CursorType = 2
rsAddComments.LockType = 3
rsAddComments.Open SQL_String, AO_GB_Connect

rsAddComments.AddNew
rsAddComments.Fields("Team") = Request.Form("txtcomments")
rsAddComments.Update

rsAddComments.Close
Set rsAddComments = Nothing
Set AO_GB_Connect = Nothing
%>
----------------------------------------------

Please help - thank you very much

Red




Replies:
Posted By: pmormr
Date Posted: 16 February 2004 at 4:35pm

just use a where clause in your select statement and then check if there are any records in the database... I.e.

Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM yourtable WHERE checkfield = 'whatever'"

If rs.eof and rs.bof then
   'add it to the database
Else
   'redirect
End if



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: redk
Date Posted: 16 February 2004 at 4:56pm

Firstly, thanks for responding :)

I have finally figured it out and for all those who are searching the net in the future and come across this thread in the hope that they find what they are looking for.......well, here is the syntax i couldn't get for two whole days but, now i have :)

SQL_String= "SELECT * FROM List WHERE Team = '"& Request.Form("txtcomments") &"' "

Lol - all those bloody colons and quotes - can get a bit messy eh? hehehe!

Thanks a lot for your help!

Red




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net