Hi - Can anybody please help with this?
Im trying to transfer some Access table values into an excel spreadsheet - Its been working for a good few years but all of a sudden and I think since converting from Access/Excel 97 to 2003 this part of the transfer has stopped working.
Error msg says "Application-defined or Object-defined error
The code below opens the excel sheet OK, works fine until it comes to the Add Conditions
Any help is much appreciated
Mike
*************************************************************************
Dim xlApp As Excel.Application, xlWKB As Excel.Workbook, xlSht As Excel.Worksheet, rng As Excel.Range
Dim db As DAO.Database, rsConditions As DAO.Recordset, strSQL As String
Set xlApp = New Excel.Application
'On Error Resume Next
xlApp.Visible = True
Set xlWKB = xlApp.Workbooks.Open("Excel spreadsheet goes here.xls")
strSQL = "SELECT tblActOpCons.ProdID, tblOpConDefs.TRCName, tblActOpCons.NumValue, tblActOpCons.TxtValve, tblOpConDefs.TypeNum " & _
"FROM tblOpConDefs INNER JOIN tblActOpCons ON tblOpConDefs.OpConDefID = tblActOpCons.OpConDefID " & _
"WHERE (((tblActOpCons.ProdID)=" & Me.cbxProduct.Value & ") AND ((tblOpConDefs.TRCName) Is Not Null)); "
Set db = CurrentDb
Set rsConditions = db.OpenRecordset(strSQL)
'Adds Names
xlWKB.Names("ProdMin").RefersToRange.Value = Me.cbxProductName.Column(0) & " - Min"
xlWKB.Names("ProdTarget").RefersToRange.Value = Me.cbxProductName.Column(0) & " - Target"
xlWKB.Names("ProdMax").RefersToRange.Value = Me.cbxProductName.Column(0) & " - Max"
'Add conditions
If rsConditions.RecordCount > 0 Then
Do Until rsConditions.EOF
Set rng = xlWKB.Names(rsConditions!TRCName).RefersToRange
If rsConditions!TypeNum = True Then
rng.Value = rsConditions!NumValue
Else
rng.Value = rsConditions!TxtValve
End If
rsConditions.MoveNext
Loop
End If
xlWKB.Sheets("RCS").PrintOut
xlWKB.Close False
xlApp.Quit
End Sub
Im trying to transfer some Access table values into an excel spreadsheet - Its been working for a good few years but all of a sudden and I think since converting from Access/Excel 97 to 2003 this part of the transfer has stopped working.
Error msg says "Application-defined or Object-defined error
The code below opens the excel sheet OK, works fine until it comes to the Add Conditions
Any help is much appreciated
Mike
*************************************************************************
Dim xlApp As Excel.Application, xlWKB As Excel.Workbook, xlSht As Excel.Worksheet, rng As Excel.Range
Dim db As DAO.Database, rsConditions As DAO.Recordset, strSQL As String
Set xlApp = New Excel.Application
'On Error Resume Next
xlApp.Visible = True
Set xlWKB = xlApp.Workbooks.Open("Excel spreadsheet goes here.xls")
strSQL = "SELECT tblActOpCons.ProdID, tblOpConDefs.TRCName, tblActOpCons.NumValue, tblActOpCons.TxtValve, tblOpConDefs.TypeNum " & _
"FROM tblOpConDefs INNER JOIN tblActOpCons ON tblOpConDefs.OpConDefID = tblActOpCons.OpConDefID " & _
"WHERE (((tblActOpCons.ProdID)=" & Me.cbxProduct.Value & ") AND ((tblOpConDefs.TRCName) Is Not Null)); "
Set db = CurrentDb
Set rsConditions = db.OpenRecordset(strSQL)
'Adds Names
xlWKB.Names("ProdMin").RefersToRange.Value = Me.cbxProductName.Column(0) & " - Min"
xlWKB.Names("ProdTarget").RefersToRange.Value = Me.cbxProductName.Column(0) & " - Target"
xlWKB.Names("ProdMax").RefersToRange.Value = Me.cbxProductName.Column(0) & " - Max"
'Add conditions
If rsConditions.RecordCount > 0 Then
Do Until rsConditions.EOF
Set rng = xlWKB.Names(rsConditions!TRCName).RefersToRange
If rsConditions!TypeNum = True Then
rng.Value = rsConditions!NumValue
Else
rng.Value = rsConditions!TxtValve
End If
rsConditions.MoveNext
Loop
End If
xlWKB.Sheets("RCS").PrintOut
xlWKB.Close False
xlApp.Quit
End Sub