kfschaefer
Registered User.
- Local time
- Today, 05:30
- Joined
- Oct 10, 2008
- Messages
- 58
I have a Database and Spreadsheet that I am attempting to update the
xls from mdb. and I need to be able to copy more than the 255
characters into 1 cell.
I
have found this code however I am running into a "Object variable or
With block variable not set (Error 91)" issue on the following.
xlWS.Cells(1, iCols + 1).Value = rs.Fields(iCols).Name
here is the code.
Thanks,
Karen
Sub Transfer_1()
Dim xlApp As Excel.Application
Dim xlWkbk As Workbook, xlWS As Worksheet
Dim rs As DAO.Recordset
Dim iCols As Integer
Set rs = CurrentDb.OpenRecordset("SELECT * FROM ZA002_TIRLData")
Set xlApp = CreateObject("Excel.Application")
Set xlWkbk = xlApp.Workbooks.Open("C:\Documents and Settings\user\My Documents\FunctionalTest\ZA002_FunctionalCheck.xls")
xlWkbk.Sheets(SheetName).Cells(1, 1).Activate
xlApp.Visible = True
For iCols = 0 To rs.Fields.Count - 1
xlWS.Cells(1, iCols + 1).Value = rs.Fields(iCols).Name
Next
xlWS.Range(xlWS.Cells(1, 1), _
xlWS.Cells(1, rs.Fields.Count)).Font.Bold = True
xlWS.Range("A2").CopyFromRecordset rs
rs.Close
Set rs = Nothing
Set xlApp = Nothing
End Sub
xls from mdb. and I need to be able to copy more than the 255
characters into 1 cell.
I
have found this code however I am running into a "Object variable or
With block variable not set (Error 91)" issue on the following.
xlWS.Cells(1, iCols + 1).Value = rs.Fields(iCols).Name
here is the code.
Thanks,
Karen
Sub Transfer_1()
Dim xlApp As Excel.Application
Dim xlWkbk As Workbook, xlWS As Worksheet
Dim rs As DAO.Recordset
Dim iCols As Integer
Set rs = CurrentDb.OpenRecordset("SELECT * FROM ZA002_TIRLData")
Set xlApp = CreateObject("Excel.Application")
Set xlWkbk = xlApp.Workbooks.Open("C:\Documents and Settings\user\My Documents\FunctionalTest\ZA002_FunctionalCheck.xls")
xlWkbk.Sheets(SheetName).Cells(1, 1).Activate
xlApp.Visible = True
For iCols = 0 To rs.Fields.Count - 1
xlWS.Cells(1, iCols + 1).Value = rs.Fields(iCols).Name
Next
xlWS.Range(xlWS.Cells(1, 1), _
xlWS.Cells(1, rs.Fields.Count)).Font.Bold = True
xlWS.Range("A2").CopyFromRecordset rs
rs.Close
Set rs = Nothing
Set xlApp = Nothing
End Sub