Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error on Recordset field update

Status
Not open for further replies.

zinvestor

MIS
Jul 16, 2010
1
US
I get a 'multiple-step operation generated errors' message from the following code:

Sub LoadShopRateData

On Error Resume Next

sql = "SELECT Job1.Job as RptJob, " _
& "b.Parent_Job, " _
& "b.Component_Job, " _
& "Job.Make_Quantity, " _
& "Job.Act_Material, " _
& "Job.Act_Service, " _
& "Job.Mat_Markup_Pct, " _
& "Job.Serv_Markup_Pct, " _
& "Job.Labor_Markup_Pct, " _
& "CAST (Sum(Job_Operation.Act_Run_Hrs*((Work_Center.Run_Labor_Rate*(Work_Center.Labor_Burden/100))+Work_Center.Run_Labor_Rate)) AS money) AS Shop_Rate_Labor " _
& "FROM (((Job Job1 LEFT JOIN (Select Parent_Job, Component_Job From Bill_Of_Jobs " _
& "Where Relationship_Type = 'Component') as b ON Job1.Job = b.Parent_Job) " _
& "LEFT JOIN Job ON b.Component_Job = Job.Job) " _
& "LEFT JOIN Job_Operation ON Job.Job = Job_Operation.Job) " _
& "LEFT JOIN Work_Center ON Job_Operation.Work_Center = Work_Center.Work_Center " _
& "WHERE Job1.Job = '" & sJob & "' " _
& "GROUP BY Job1.Job, b.Parent_Job, b.Component_Job, Job.Make_Quantity, Job.Act_Material, Job.Act_Service, " _
& "Job.Mat_Markup_Pct, Job.Serv_Markup_Pct, Job.Labor_Markup_Pct "

CloseRS(oRS)
oRS.Open sql, oConn, adOpenDynamic, adLockPessimistic

Set oRS.ActiveConnection = Nothing

Dim strErrMsg
Dim oRS_ShopRate
Set oRS_ShopRate = CreateObject("ADODB.Recordset")

If (Not (oRS.BOF AND oRS.EOF)) and oRS("RptJob") = oRS("Parent_Job") Then
' Loop Recordset and Load Costs by reading through the bill of jobs to get all the underlying components for each component in oRS
Do Until oRS.EOF
Erase JobArray
ReDim JobArray(0)

oCmn.JCRecursion_80 oRS("Component_Job"), JobArray
sJobText = vbNullString

For y = 0 To UBound(JobArray)
sJobText = sJobText & "'" & oCmn.PrepareMaterial(JobArray(y)) & "'"
If y <> UBound(JobArray) Then sJobText = sJobText & ", "
Next

sJobText = " IN (" & sJobText &") "

sql = "SELECT sum(Job.Act_Material) as actMat, sum(Job.Act_Service) as actServ, " _
& "CAST (Sum(jo.rate) AS money) AS Shop_Rate_Labor " _
& "FROM Job LEFT JOIN (select Job_Operation.job, CAST (sum(Job_Operation.act_run_hrs * " _
& "((Work_Center.Run_Labor_Rate * (Work_Center.Labor_Burden/100)) + Work_Center.Run_Labor_Rate)) AS money) as rate " _
& "from Job_Operation LEFT JOIN Work_Center ON Job_Operation.Work_Center = Work_Center.Work_Center group by job) as jo ON Job.Job = jo.Job " _
& "WHERE Job.Job " & sJobText & " "

oRS_ShopRate.Open sql, oConn, adOpenStatic, adLockReadOnly

oRS(4) = oRS_ShopRate(0)
if Err.number <> 0 then
strErrMsg = "Error: " & Err.Number & vbCR & "Source: " & Err.Source & vbCR & "Desc: " & Err.Description & vbCR
strErrMsg = strErrMsg & "oRS(4) = " & oRS(4) & " Type = " & oRS(4).Type & vbCR
strErrMsg = strErrMsg & "oRS_ShopRate(0) = " & oRS_ShopRate(0) & " Type = " & oRS_ShopRate(0).Type & vbCR
MsgBox strErrMsg
Err.Clear
end if
oRS(5) = oRS_ShopRate(1)
if Err.number <> 0 then
strErrMsg = "Error: " & Err.Number & vbCR & "Source: " & Err.Source & vbCR & "Desc: " & Err.Description & vbCR
strErrMsg = strErrMsg & "oRS(5) = " & oRS(5) & " Type = " & oRS(5).Type & vbCR
strErrMsg = strErrMsg & "oRS_ShopRate(1) = " & oRS_ShopRate(1) & " Type = " & oRS_ShopRate(1).Type & vbCR
MsgBox strErrMsg
Err.Clear
end if
oRS(9) = oRS_ShopRate(2)
if Err.number <> 0 then
strErrMsg = "Error: " & Err.Number & vbCR & "Source: " & Err.Source & vbCR & "Desc: " & Err.Description & vbCR
strErrMsg = strErrMsg & "oRS(9) = " & oRS(9) & " Type = " & oRS(9).Type & vbCR
strErrMsg = strErrMsg & "oRS_ShopRate(2) = " & oRS_ShopRate(2) & " Type = " & oRS_ShopRate(2).Type & vbCR
MsgBox strErrMsg
Err.Clear
end if


oRS.Update

oRS_ShopRate.Close

oRS.MoveNext
Loop
End If

tblShopRate.SetDataSource oRS, 3
CloseRS(oRS)
On Error GoTo 0
End Sub

The error comes on the 'oRS(9) = oRS_ShopRate(2)' line
The error message is:

---------------------------

---------------------------
Error: -2147217887
Source: Microsoft Cursor Engine
Desc: Multiple-step operation generated errors. Check each status value.
oRS(9) = 0 Type = 6
oRS_ShopRate(2) = 261.775 Type = 6

---------------------------
OK
---------------------------

I have had this problem in the past where there were data conversion problems, but as you can see from the types in the above message, both fields are currency (money).

The database is MS SQL Server (being converted from Access). In Access, I used the cCur Function to perform the conversion and everything worked fine. With SQL Server I am using the CAST x to money construct and getting the failure. Any insights into correcting this will be appreciated.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top