Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset Searches James McDowell[_2_] Excel Programming 3 July 11th 06 11:20 PM
How to locate the end of a recordset CLamar Excel Programming 3 June 1st 06 07:16 PM
Need ADO Recordset Help Mr B[_2_] Excel Programming 9 April 21st 06 04:51 PM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM
Recordset Stephan Kassanke Excel Programming 0 September 10th 03 04:45 PM


All times are GMT +1. The time now is 09:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"