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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a record to a database

Status
Not open for further replies.

Kevin123456

Technical User
Jan 14, 2002
35
0
0
GB
Hi,

I'm using an Access 97 database and can read the records from it with no problems. I also have one set of statements that adds data with no problems. The statements are:

Dim LConnect, LResults, LReason, LError, LStamp
Set LConnect = Server.CreateObject ("ADODB.Connection")
LConnect.Open "UMS"
Set LResults = Server.CreateObject ("ADODB.Recordset")
LResults.Open "SELECT * FROM log WHERE Error = '" & Error & "'", LConnect, adOpenDynamic,adLockOptimistic
LResults.AddNew
LResults ("Reason") = Reason
LResults ("Error") = Error
LResults ("Stamp") = Now()
LResults.Update
LResults.Close

Another set of statements to insert records into another table produce:

ADODB.Recordset error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

reg.asp, line 88

The code here is:

Dim UConnect, UResults, UReason, UError, UStamp
Set UConnect = Server.CreateObject ("ADODB.Connection")
UConnect.Open "UMS"
Set UResults = Server.CreateObject ("ADODB.Recordset")
UResults.Open "SELECT * FROM User", UConnect, adOpenDynamic,adLockOptimistic
UResults.AddNew
RESPONSE.WRITE("GOT HERE")
UResults ("Username") = Results("Username")

Line 87 is the last line of the second set of statements and I see the 'Got Here' progress trap. I think the problem is in the query of the database that I'm using, I don't really understand why I need to use a query and not just specify the table I want to insert the data in. I understand that the error message concerns an empty recordset being returned (even though there are two records in the table). The first set of statements needn't necessarily return any data as it could be the first time that the error code has been written to the log table. There is an ID field that's the primary key which is an autonumber however I'm assuming that Access will automatically fill that in when it inserts the row and I'm using the include file adovbs.inc.

Any help very gratefully appreciated

Kevin
 
Kevin,

You can...

<b>URESULTS.OPEN &quot;User&quot;,UConnect, dOpenDynamic,adLockOptimistic</b>


Thats it!

Cheers!

 
In this line:
UResults (&quot;Username&quot;) = Results(&quot;Username&quot;)

What is in the recordset Results? I see in your code a Recordset named LResults and one named UResults, but not one named Results?

 
Thanks for the responses.

After I looked back at the code I saw that I had a results.movenext rather than an AResults.movenext. This has been superceeded by a simple AResults.RecordCount. The code now gets virtually to the end but there's a Yes/No field that I want to show as yes (ticked in the database field). The code I'm using is:

UResults (&quot;New&quot;) = &quot;on&quot;

I now get a Type Mismatch error, can anyone suggest how I answer pass the Yes?

Thanks.
 
Maybe you can try &quot;TRUE&quot; or &quot;FALSE&quot;? ------------------
Freedom is a Right
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top