Hi all,
I am lost in confusion here. I am trying to update an ole object in a table using the following:
Sub ProcesstableTARReport()
Dim dbs As dao.Database
Dim rst As dao.Recordset
Dim Counter As Integer
Dim mySQL As String
On Error GoTo ErrHandler
‘ Reference to database
Set dbs = CurrentDb
‘ Open recordset from table
mySQL = “SELECT Pricing.Modified_Pricing_ID, Pricing.[Technical Report] from Pricing WHERE Pricing.Modified_Pricing_ID= ‘” & [Forms]![Splash Screen]![vLastPricing] & “‘”
Set rst = dbs.OpenRecordset(mySQL, dbOpenDynaset)
‘ mySQL = “UPDATE Pricing ” & _
‘ “SET Pricing.[Desk_TAR_Complete] = True ” & _
‘ “WHERE Pricing.Pricing_ID In (” & vPricingPackage & “)”
‘ DoCmd.RunSQL mySQL ‘for the table named pricing to update TAR ID COde
‘ find number of records
Counter = rst.RecordCount
‘ loop through records of imported table
Do While Not rst.EOF
‘ loop through fields (starting with 3rd field)
‘ originally had For i = 2 To rstTemp.Fields.Count
For i = 0 To Counter
DoCmd.OpenForm “frmSelectFileXP”, acNormal, , , , acDialog
oleTechnicalReport.Class = “Excel.Sheet” ‘ Set class name.
‘ Specify type of object.
oleTechnicalReport.OLETypeAllowed = acOLELinked
‘ Specify source file.
oleTechnicalReport.SourceDoc = Forms![frmSelectFileXP]![vTARReportName]
‘ Specify data to create link to.
‘TechnicalReport.SourceItem = “R1C1:R25C15”
‘ Create linked object.
oleTechnicalReport.Action = acOLECreateLink
‘ Adjust control size.
oleTechnicalReport.SizeMode = acOLESizeZoom
Next i
rst.MoveNext
Loop
ExitHandler:
‘ Clean up
On Error Resume Next
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
In this case, the Pricing Table is a linked table, the object is an excel spreadsheet on our network. The path of the spreadsheet is captured in the line …DoCmd.OpenForm “frmSelectFileXP”, acNormal, , , , acDialog …
Right now as the code exists, I am getting an object required error. This code worked when I was updating the table through a form and updating only one record at a time. I am trying to use the sql statement to generate a recordset of the records I want to update and then scroll through the records udating them in one shot.
I put this code togehter using peices of code that worked individually before when applying the logic to a single reocrd on a form. Don’t know where to go from here.
Can someone point me in the right direction.
Thanks