OutFront Forums
     Home    Register     Search      Help      Login    

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

Sponsors
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

 

Preventing Duplicate Entries in Access via ASP

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP, PHP, and Database >> Preventing Duplicate Entries in Access via ASP
Page: [1]
 
Professional Website Management
hawleyr

 

Posts: 21
Joined: 8/24/2007
Status: offline

 
Preventing Duplicate Entries in Access via ASP - 9/16/2009 11:55:39   
I used the suggested page http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=106 to help me out on my problem; however, I'm still getting and error. I think I may have misplaced a line of code. Could anyone give me a hand?

My current form posts to this asp page:
<%
'Dimension variables
Dim adoCon          'Holds the Database Connection Object
Dim rsAddComments   'Holds the recordset for the new record to be added
Dim strSQL          'Holds the SQL query to query the database

	'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

	'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("../fpdb/ResourceRequest2008.mdb")

	'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")

	'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT Investigator.First_Name, Investigator.Last_Name, Investigator.Institution, Investigator.Department, Investigator.Street1, Investigator.Street2, Investigator.City, Investigator.State, Investigator.Postal_Code, Investigator.Country, Investigator.Phone, Investigator.Fax, Investigator.Email, Investigator.Inserted_Date FROM Investigator WHERE Email = '" & _
            Request.Form("Email") & "'"

  Set rs = db.Execute()
    If rs.EOF Then
  
	'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorLocation = 3
rsAddComments.CursorType = 2

	'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3

	'Open the recordset with the SQL query
rsAddComments.Open strSQL, adoCon 	

	'Tell the recordset we are adding a new record
rsAddComments.AddNew	

		'Add a new record to the recordset
rsAddComments.Fields("First_Name") = Request.Form("First_Name")
rsAddComments.Fields("Last_Name") = Request.Form("Last_Name")
rsAddComments.Fields("Institution") = Request.Form("Institution")
rsAddComments.Fields("Department") = Request.Form("Department")
rsAddComments.Fields("Street1") = Request.Form("Street1")
rsAddComments.Fields("Street2") = Request.Form("Street2")
rsAddComments.Fields("City") = Request.Form("City")
rsAddComments.Fields("State") = Request.Form("State")
rsAddComments.Fields("Postal_Code") = Request.Form("Postal_Code")
rsAddComments.Fields("Country") = Request.Form("Country")
rsAddComments.Fields("Phone") = Request.Form("Phone")
rsAddComments.Fields("Fax") = Request.Form("Fax")
rsAddComments.Fields("Email") = Request.Form("Email")

' Insert User IP address
'rsAddComments.Fields("UserIP") = request.ServerVariables("REMOTE_HOST") 

' Insert the current time
rsAddComments.Fields("Inserted_Date") = Date()

	'Write the updated recordset to the database
rsAddComments.Update

	'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing

Else
    Response.Write "Record exists"
  End If  
%>


When the form posts I get:
Microsoft VBScript runtime error '800a01a8'
Object required: 'db'
/ResourceDB/Investigator_Add.asp, line 20

Line 20 of the code is:
  Set rs = db.Execute()


I'm also concerned my final lines of code for response.write is in the wrong place.

Thank you for any help!
TexasWebDevelopers

 

Posts: 884
Joined: 2/22/2002
From: Dallas, TX
Status: offline

 
RE: Preventing Duplicate Entries in Access via ASP - 9/16/2009 14:00:19   
Your connection object is adoCon not db

Here is the whole process at it's most basic:

<%
DIM DBConn, ConnectStr, Sql, Rs
Set DBConn = Nothing
Set DBConn = Server.CreateObject("ADODB.Connection")
ConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database.mdb")
DBConn.Open ConnectStr
sql = "SELECT [fieldname] FROM [tablename] "
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open sql, DBConn, 3, 3
Do While Not Rs.EOF
fieldname=Rs("fieldname")
Response.write(fieldname & "<br>")
Rs.MoveNext
Loop
Rs.Close
Set DBConn = Nothing
%>

Create a connection to the database and open the connection>>query the database with a sql statement>>create the recordset of data>>loop through all of the records and write out your data.

_____________________________

:)

Follow us on TWITTER

(in reply to hawleyr)
hawleyr

 

Posts: 21
Joined: 8/24/2007
Status: offline

 
RE: Preventing Duplicate Entries in Access via ASP - 9/16/2009 15:21:03   
*smacks forehead*

Thanks!

(in reply to TexasWebDevelopers)
Page:   [1]

All Forums >> Web Development >> ASP, PHP, and Database >> Preventing Duplicate Entries in Access via ASP
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts