Solved

2147217887 ODBC call failed When performing a recordset update

Posted on 2004-08-20
7
1,530 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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 500 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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