Solved

2147217887 ODBC call failed When performing a recordset update

Posted on 2004-08-20
7
1,510 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading the Contents of a Directory In Access VBA 5 68
passing parameter in sql procedure 9 61
VBA Shell can't Find Word document 11 92
Add and format columns in vb6 7 56
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

786 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