?
Solved

2147217887 ODBC call failed When performing a recordset update

Posted on 2004-08-20
7
Medium Priority
?
1,630 Views
Last Modified: 2013-12-25
When I attempt to perform a recordset update I get this error: 2147217887 ODBC call failed
I can see that it retrieves the values that I want to insert however it fails at the update...What am I missing? Please help!!

Private Sub cmdFrmResched_Click()
On Error GoTo Err_cmdFrmResched_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim cnndb   As Connection
    Dim rstAppt As ADODB.Recordset
    Dim rstRes  As ADODB.Recordset
    Dim intApptID   As Integer
    Dim intPO As Long
    Dim strSQL As String


   
    Set cnndb = Application.CurrentProject.Connection
    Set rstAppt = New ADODB.Recordset
    Set rstRes = New ADODB.Recordset
 
   
    'rstAppt.Open "tblAppt", cnndb, adOpenForwardOnly, adLockPessimistic
    rstAppt.Open "tblAppt", cnndb, adOpenDynamic, adLockOptimistic
    rstRes.Open "tblApptResched", cnndb, adOpenForwardOnly, adLockPessimistic
   
    intApptID = Me!ApptID
   
    rstAppt.Find "ApptID = " & Me!ApptID
   
    intPO = rstAppt!PONo
   
    With rstAppt
        .AddNew
        !PONo = intPO
        !ApptCont = Me.ApptCont
        !DTStampEnter = Now
        .Update                                    <-----It errors when it performs this step
    End With
   
    With rstRes
        .AddNew
        !ApptID = Me!ApptID
        !NewID = rstAppt.Fields("ApptID")
        .Update
    End With
   
    'move appointment to Rescheduled
    Me.Status = "R"
   
    DoCmd.RunCommand acCmdSaveRecord
   
    DoCmd.SetWarnings False
   
    'append the "R" and "C" records to history
    DoCmd.OpenQuery "qryApptHistoryR"
   
    'reassign PO records to new appt id
    DoCmd.RunSQL "UPDATE tblApptPO SET tblApptPO.ApptID = " _
        & rstAppt.Fields("ApptID") & " WHERE tblApptPO.ApptID= " & Me!ApptID

    'update Locations to new appt
    DoCmd.RunSQL "UPDATE tblLoc SET tblLoc.ApptID = " _
        & rstAppt.Fields("ApptID") & " WHERE tblLoc.ApptID= " & Me!ApptID
   
    'Delete the appointment from Current
    DoCmd.RunSQL "DELETE tblAppt.* FROM tblAppt " _
        & "Where tblAppt.ApptID = " & Me!ApptID
       
    DoCmd.SetWarnings True
       
    stDocName = "frmApptResch"
    stLinkCriteria = "[ApptID] = " & rstAppt.Fields("ApptID")
    DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit

    DoCmd.Close acForm, "frmAppt"
   
Exit_cmdFrmResched_Click:
       
    rstAppt.Close
    rstRes.Close
    Exit Sub

Err_cmdFrmResched_Click:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_cmdFrmResched_Click
   
End Sub
0
Comment
Question by:infutech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Expert Comment

by:PePi
ID: 11852663
<snip>  
    Set cnndb = Application.CurrentProject.Connection
    Set rstAppt = New ADODB.Recordset
    Set rstRes = New ADODB.Recordset
 
    rstAppt.CursorLocation = adUseClient                        '<==== Add these 2 lines
    rstRes.CursorLocation = adUseClient

   
    'rstAppt.Open "tblAppt", cnndb, adOpenForwardOnly, adLockPessimistic
    rstAppt.Open "tblAppt", cnndb, adOpenDynamic, adLockOptimistic
    rstRes.Open "tblApptResched", cnndb, adOpenForwardOnly, adLockPessimistic

    'also change the above code to
    rstAppt.Open "tblAppt", cnndb, adOpenDynamic, adLockPessimistic
    rstRes.Open "tblApptResched", cnndb, adOpenDynamic, adLockPessimistic
</snip>

if this fails, try retrieving the recordset by using an SQL statement rather than retrieving the table

   rstAppt.Open "SELECT * FROM tblAppt", cnndb, adOpenDynamic, adLockPessimistic
   rstRes.Open "SELECT * FROM tblApptResched", cnndb, adOpenDynamic, adLockPessimistic



0
 
LVL 29

Expert Comment

by:leonstryker
ID: 11853702
I would change this:

rstAppt.Open "tblAppt", cnndb, adOpenDynamic, adLockOptimistic

to this:

rstAppt.Open "Select * From tblAppt", cnndb, adOpenDynamic, adLockOptimistic

Leon
0
 

Author Comment

by:infutech
ID: 11854309
Thanks for the help, however niether of these two suggestions seem to work. For some reason when it gets to the .Update it goes directly to the error. It does not want to update. I am not sure why.
0
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!

 

Author Comment

by:infutech
ID: 11854347
Is there a way i can insert a new record and return the unique apptid that is generated from the new record? That is ultimately what is being done.
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 11854354
Ok, why don't you scrap the update method and run the SQL INSERT  and DELETE statements instead and requery the recordset afterwards.

Leon
0
 
LVL 6

Expert Comment

by:PePi
ID: 11855862
<snip>
Is there a way i can insert a new record and return the unique apptid that is generated from the new record? That is ultimately what is being done.
</snip>

what DB are you using? Access? SQL Server?

if it's SQL Server, you can easily create a stored procedure when you insert a record and will return the unique ID for the inserted record.

if  it's access, i guess after INSERTing the new record, you can just requery just like what leon said.


0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 2000 total points
ID: 11862991
i do not think ur error is becuase of the first update command .. it must be because of ur second upodate command
With rstRes
        .AddNew
        !ApptID = Me!ApptID
        !NewID = rstAppt.Fields("ApptID")
        .Update
    End With

becuase rstRes has been opened as a forwardonly cursor ...
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 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