Solved

2147217887 ODBC call failed When performing a recordset update

Posted on 2004-08-20
7
1,468 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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:infutech
Comment Utility
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
Comment Utility
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
Comment Utility
<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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now