Solved

updating recordsets

Posted on 1998-12-07
2
186 Views
Last Modified: 2013-12-25
I need to allow users to update/modify Access records throught a browser. They search with a form (based on a primary key in Access) and when the result shows up, they can modify as they need. The only things I know about ASPs is form the Beginning and Professional Active Server Pages 2.0 books from Wrox Press.

Here's the code where the error lies:
-------------------------------------
        ' name of this file is /boogie/modifyresults.asp
        dim primary_key
      ' create the recordset object
      Set objRec = Server.CreateObject ("ADODB.Recordset")

      ' open the recordset object (tried w/o Batch also)
      objRec.Open "MyDB", strConnect, adOpenKeyset, _
            adLockBatchOptimistic, adCmdTable

      primary_key = Request.Form("Primary_key")
        ' find the record with the primary key they entered
      objRec.Find "Primary_key = 'primary_key'", 0, _
                  adSearchForward
      If objRec.EOF Then
         objRec("Field2") = Request.Form("NewField2")
         objRec("Field3") = Request.Form("NewField3")
           .....
      objRec.UpdateBatch    'tried without the Batch also
      Else
        Response.Write "Couldn't find the record<BR>"
      End If
      
      ' now close and clean up
      objRec.Close
      Set objRec = Nothing
-------------------------------------

The error message I get is
ADODB.Recordset error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted; the operation requested by the application requires a current record.

/boogie/modifyresults.asp, line 40

MS's Knowledge Base didn't help. Line 40 of the file is:
         objRec("Field2") = Request.Form("NewField2")

Please help ASAP. Thanks.
0
Comment
Question by:Pakfan
2 Comments
 
LVL 1

Accepted Solution

by:
suden earned 150 total points
ID: 1856946
Hi,

Change your following code

If objRec.EOF AND objRec.BOF Then
   objRec("Field2") = Request.Form("NewField2")
   objRec("Field3") = Request.Form("NewField3")
           .....
objRec.UpdateBatch    'tried without the Batch also
Else
  Response.Write "Couldn't find the record<BR>"
End If


in ADO if recordset is empty then both eof and box are true so to check that you have any record in your recordset you should check both EOF and BOF.

Suden
0
 

Author Comment

by:Pakfan
ID: 1856947
That gets rid of the error message for the time being but the record does not get updated. According to the book, it looks like I had the actions reversed. Apparently, the line
   objRec("Field2") = Request.Form("NewField2")
should be in the Else statement, not in the If part. Either way, the recordset does not get updated. Thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question