[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

updating recordsets

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
Pakfan
Asked:
Pakfan
1 Solution
 
sudenCommented:
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
 
PakfanAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now