+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    02-24-2010
    Location
    Veenendaal
    MS-Off Ver
    Excel 2003
    Posts
    2

    External data directly into an array

    I am trying to get external data from a paradox table directly into an array. But I have no idea where to start. I was trying to do it with a ADODB.connection and recordset but that doesn't seem to work since I am using a ODBC connection.

    Code:
    Sub Get_Data_Into_Array()
    'A reference must be made to the Microsoft ActiveX Data Object Library x.x
    'via Tools | References... in the VB-editor.
    Dim cnt As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim stSQL As String
    Dim vaData As Variant
    Dim i As Long, j As Long
    
    'Instantiate the new ADO-objects.
    Set cnt = New ADODB.Connection
    Set rst = New ADODB.Recordset
    
    'Create the SQL-statement
    stSQL = "SELECT * FROM HORDERRG"
    
    'Connect to the databasesource.
    With cnt
        .Provider = "MSDASQL"
        .ConnectionString = "DSN=test2; DBQ=HORDERRG.DB"
        .Open
    End With
    
    'Open the recordset.
    rst.Source = strSQL
    rst.ActiveConnection = cnt
    rst.Open
    
    
    'Get some data about the recordset.
    With rst
        i = .Fields.Count
        j = .RecordCount
    End With
    
    'Transfer the recordset to the array of variant-type.
    vaData = rst.GetRows()
    
    'Testing purpose only
    Debug.Print UBound(vaData) + 1 'Due to 0-based array
    Debug.Print "Number of fields = " & i
    Debug.Print "Number of records = " & j
    
    'Disconnect and empty memory.
    rst.Close
    Set rst = Nothing
    cnt.Close
    Set cnt = Nothing
    
    End Sub
    This is what I've got so far. But that doesn't work. Can somebody help me?

    -----------------
    I had the wrong connectionstring
    Last edited by AnnaAngel; 03-03-2010 at 07:36 AM.

  2. #2
    Forum Moderator pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,141

    Re: External data directly into an array

    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    JBeaucaires Excel Files

    VBA for smarties - snb

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0