Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check table for duplicates before inserting new records.. ERROR 1

Status
Not open for further replies.

Anthony904

IS-IT--Management
Jul 15, 2004
153
US
Hi,

I am trying to check for duplicates before inserting into my Access Table.

I am getting an error.
Code:
Microsoft VBScript runtime error '800a01a8' 

Object required: '' 

/aspx/ip21/Survey_Process.asp, line 87

Code:
	Dim name, date1, Building
	Dim sConnString, connection, sSQL, RS

	' Receiving values from Form, assign the values entered to variables
	name = Request.Form("name")
	date1 = Request.Form("date1")
	Building =Request.Form("Building")
	
	'Add check here for duplicates before INSERT
	'If Duplicate found .. display duplicate and go correct.

[COLOR=red]set RS = connection.execute("select * from Sugg_tbl where Name = '"& request("Name") &"' ")[/color]

        if RS.EOF = True then
 	'no duplicate of new data found, so insert data
 	
	'declare SQL statement that will query the database 
	sSQL = "INSERT into Sugg_tbl (name, date1, Building) values ('" & _
	name & "', '" & date1 & "', '" & Building & "')" 
         
        else
        
        response.write "duplicate found"

	End If
	
	'define the connection string, specify database 
	'driver and the location of database
	sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ 
	"Data Source=" & Server.MapPath("asc.mdb") 


	'create an ADO connection object 
Set connection = Server.CreateObject("ADODB.Connection") 
set rs = Server.CreateObject("ADODB.recordset")

Any Ideas?

Thanks!
 
I see where you've dim'ed your connection object but not where you've actually instantiated it, thus there is no connection object from which you can create your recordset. You'll need to first instantiated connection and then go from there.
Code:
set connection = [COLOR=green]'however you connect to your DB[/color]
set RS = connection.execute("select * from Sugg_tbl where Name = '"& request("Name") &"' ")

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Thanks for the response..

I did as you suggested... and am now getting a different error...

Code:
ADODB.Connection error '800a0e78' 

Operation is not allowed when the object is closed. 

/aspx/ip21/Survey_Process.asp, line 91

line 91
Code:
set rs = connection.execute("select * from Sugg_tbl where Name = '"& request("Name") &"' ")

I added the line in read to try to open.. nogo..
Code:
	'create an ADO connection object 
Set connection = Server.CreateObject("ADODB.Connection") 
Set rs = Server.CreateObject("ADODB.recordset")

        set rs = connection.execute("select * from Sugg_tbl where Name = '"& request("Name") &"' ")
        
        [COLOR=red]rs.open sSQL, connection[/color]
        if RS.EOF = True then
 
Ok, you set the connection object to a adodb.connection, but you haven't yet properly defined it. For example (from for a SQL DB):
Code:
"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
I'm not sure I understand...

I thought I was defining it here..

Code:
	'create an ADO connection object 	
	'define the connection string, specify database 
	'driver and the location of database
	sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ 
	"Data Source=" & Server.MapPath("asc.mdb") 
	
	'Open the connection to the database
	connection.Open(sConnString)

Thanks for the input..
 
Ok, you did, but you did all of that *after* you tried using it to open your recordset. You need to do that *before* you open your recordset.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top