Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

2147217887 ODBC call failed When performing a recordset update

Posted on 2004-08-20
7
Medium Priority
?
1,675 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses

618 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