verno_25_02
10-30-2004, 10:47 PM
Hi,
Have a quick question on a problem thats been driving me nuts all night. Here is what I am looking to do. I am accessing a MS Access database and grabing files and putting them into a recordset. I then want to put some of the information from this recordset in an Excel template which is opened up.
Here is where I am stuck. I can get all the way to the point of opening up the Excel file. However once opened up I cannot get the recordset data to print in the cell at all.
Here is my code that does not work. It runs like it processes everything except the part that writes to the opened Excel file.
Set oExcel = Excel.Application
oExcel.Visible = True
Set oWB = oExcel.Workbooks.Open("C:\Path To File.xls")
Set oWS = ActiveWorkbook.Worksheets("Cover")
While Not rsCust.EOF
With rsCust
If IsNull(.Fields("CompanyName").Value) Then
oWS.Cells(11, 3) = "Test" 'Places Test If No Value For Company Name
Else
oWS.Cells(11, 3) = rsCust!CompanyName 'Places Company Name If There Is A Value
End If
.MoveNext
End With
Wend
This code however will work and will print Test in the cell on the opened Excel file.
Set oExcel = Excel.Application
oExcel.Visible = True
Set oWB = oExcel.Workbooks.Open("C:\Path To File.xls")
Set oWS = ActiveWorkbook.Worksheets("Cover")
oWS.Cells(11, 3) = "Test" 'Why Will This Only Work If This Line Of Code Is In This Spot??
While Not rsCust.EOF
With rsCust
If IsNull(.Fields("CompanyName").Value) Then
oWS.Cells(11, 3) = "Test" 'Places Test If No Value For Company Name
Else
oWS.Cells(11, 3) = rsCust!CompanyName 'Places Company Name If There Is A Value
End If
.MoveNext
End With
Wend
Thanks for your help, and if you need me to elaborate any further to clear up any questions please let me know.
Have a quick question on a problem thats been driving me nuts all night. Here is what I am looking to do. I am accessing a MS Access database and grabing files and putting them into a recordset. I then want to put some of the information from this recordset in an Excel template which is opened up.
Here is where I am stuck. I can get all the way to the point of opening up the Excel file. However once opened up I cannot get the recordset data to print in the cell at all.
Here is my code that does not work. It runs like it processes everything except the part that writes to the opened Excel file.
Set oExcel = Excel.Application
oExcel.Visible = True
Set oWB = oExcel.Workbooks.Open("C:\Path To File.xls")
Set oWS = ActiveWorkbook.Worksheets("Cover")
While Not rsCust.EOF
With rsCust
If IsNull(.Fields("CompanyName").Value) Then
oWS.Cells(11, 3) = "Test" 'Places Test If No Value For Company Name
Else
oWS.Cells(11, 3) = rsCust!CompanyName 'Places Company Name If There Is A Value
End If
.MoveNext
End With
Wend
This code however will work and will print Test in the cell on the opened Excel file.
Set oExcel = Excel.Application
oExcel.Visible = True
Set oWB = oExcel.Workbooks.Open("C:\Path To File.xls")
Set oWS = ActiveWorkbook.Worksheets("Cover")
oWS.Cells(11, 3) = "Test" 'Why Will This Only Work If This Line Of Code Is In This Spot??
While Not rsCust.EOF
With rsCust
If IsNull(.Fields("CompanyName").Value) Then
oWS.Cells(11, 3) = "Test" 'Places Test If No Value For Company Name
Else
oWS.Cells(11, 3) = rsCust!CompanyName 'Places Company Name If There Is A Value
End If
.MoveNext
End With
Wend
Thanks for your help, and if you need me to elaborate any further to clear up any questions please let me know.