Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ADO recordset
With considerable help from this DG, I've written this code that successfully
returns records from an Access db to Excel. Sub Test() Dim cn As ADODB.Connection Dim rec As ADODB.Recordset Dim nCol As Integer Set cn = New Connection Set rec = New Recordset 'Open the connection cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=\\oprdgv1\depart\Finance\" & _ "_Health Solutions Group\Customer\Customer.mdb" & ";" 'Open the recordset rec.Open "SELECT * FROM tblTESTING" & ";", cn, adOpenForwardOnly, adLockOptimistic 'Returns recordset to Excel, including the header record For nCol = 1 To rec.Fields.Count Sheets("Sheet1").Cells(1, nCol).Value = rec.Fields(nCol - 1).Name Next nCol Sheets("Sheet1").Cells(2, 1).CopyFromRecordset rec Set rec = Nothing Set cn = Nothing End Sub What I REALLY want to do now is use a "virtual recordset" as an argument in another Excel function. Because the set of data I have exceeds Excels row limitations, I have the data stored in Access, but need to use that data as an argument in Excel's LINEST function. How would I proceed with this? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
ADO recordset
I have Excel 2002. In VBA the LINEST function will not handle an array
with more rows than 65536. So it seems you need Excel 2007 or you settle for using only 65536 rows of data. Merjet |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
ADO recordset
Here's code that you might be able to use. It is self
explanatory - Beats having to buy xl2007 for the 65536+ rows HTH Sub LargeFileImport() 'Bernie Deitrick's code for opening vary large text files in Excel - more than 65536 ' rows 'Dimension Variables Dim ResultStr As String Dim FileName As String Dim FileNum As Integer Dim Counter As Double 'Ask User for File's Name FileName = Application.GetOpenFilename 'Check for no entry If FileName = "" Then End 'Get Next Available File Handle Number FileNum = FreeFile() 'Open Text File For Input Open FileName For Input As #FileNum 'Turn Screen Updating Off Application.ScreenUpdating = False 'Create A New WorkBook With One Worksheet In It Workbooks.Add Template:=xlWorksheet 'Set The Counter to 1 Counter = 1 'Loop Until the End Of File Is Reached Do While Seek(FileNum) <= LOF(FileNum) 'Display Importing Row Number On Status Bar Application.StatusBar = "Importing Row " & Counter & " of text file " _ & FileName 'Store One Line Of Text From File To Variable Line Input #FileNum, ResultStr 'Store Variable Data Into Active Cell If Left(ResultStr, 1) = "=" Then ActiveCell.Value = "'" & ResultStr Else ActiveCell.Value = ResultStr End If If ActiveCell.Row = 65536 Then 'If On The Last Row Then Add A New Sheet ActiveWorkbook.Sheets.Add Else 'If Not The Last Row Then Go One Cell Down ActiveCell.Offset(1, 0).Select End If 'Increment the Counter By 1 Counter = Counter + 1 'Start Again At Top Of 'Do While' Statement Loop 'Close The Open Text File Close 'Remove Message From Status Bar Application.StatusBar = False End Sub "merjet" wrote: I have Excel 2002. In VBA the LINEST function will not handle an array with more rows than 65536. So it seems you need Excel 2007 or you settle for using only 65536 rows of data. Merjet |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Recordset Searches | Excel Programming | |||
How to locate the end of a recordset | Excel Programming | |||
Need ADO Recordset Help | Excel Programming | |||
Type recordset/recordset? | Excel Programming | |||
Recordset | Excel Programming |