Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Help With Detecting Duplicate Entries
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Help With Detecting Duplicate Entries

 Post Reply Post Reply
Author
redk View Drop Down
Groupie
Groupie


Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 48
Post Options Post Options   Thanks (0) Thanks(0)   Quote redk Quote  Post ReplyReply Direct Link To This Post Topic: Help With Detecting Duplicate Entries
    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

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post 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



Edited by pmormr
Back to Top
redk View Drop Down
Groupie
Groupie


Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 48
Post Options Post Options   Thanks (0) Thanks(0)   Quote redk Quote  Post ReplyReply Direct Link To This Post 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



Edited by redk
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.