Results 1 to 3 of 3

Thread: Reading Access tables using INNER JOIN

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    15

    Reading Access tables using INNER JOIN

    Below is my code to read records from two acces tables using VBA in xl2007 - rather than reading specific fields - I use the 'FROM *' - so I figure this is much faster than having a much longer and complicated SQL statement - hower my records sets can be very large (Recordcount>20K and FieldCount>30) - should I be concerned about memory usage - or is the memory released by a RstRcd.Close line in my code.

    I would be interested in comments of using a complicated SQL statement with WHERE and >= clauses and so on Vs the memory concern by just reading the lot.

    Second question:
    I immdeiately copy the data into a temporary sheet - so I can use the Sort function in Excel - I know of no way to easily sort multidimentional arrays - If anybody has a good sort routine for sorting arrays I would appreciate a copy - I looked at Chip Pearson's code example - but it only handles single dimentional arrays.

    Third Question:
    The ADO connection has a memory leak - was covered in earlier post here - any suggestion what to use as alternative - should I use an ODBC connection or similar - This is all new to me - so I am not sure if I am going to have memory issues.

    Code:
        Set adoConn = CreateObject("ADODB.Connection")
        Set RstRcd = CreateObject("ADODB.Recordset")
        On Error Resume Next
        With adoConn
            Err.Clear
            .provider = "Microsoft.Jet.Oledb.4.0"
            .Properties("Jet OLEDB:Database Password") = DB_PW
            .Open "Data Source=" & strDBPath
            If Err.Number <> 0 Then
                On Error GoTo 0
                MsgBox "Cannot find database - select another"
                Exit Sub
            End If
        End With
        '***** Reads the SampleHeader/SampleData Tables - using relationship
        strTable = "SampleHeader"
        Application.StatusBar = "Reading Access table --- 'SampleHeader'"
        Astr = "SELECT * FROM (SampleHeader INNER JOIN SampleData ON SampleHeader.SampleID = SampleData.SampleID) INNER JOIN Parameter ON SampleData.ConstituentID = Parameter.ParameterID"
        RstRcd.Close
        RstRcd.Open Astr, adoConn, 3, 3
        '*******  Copies the entire dataser into worksheet "TempData" -- in ThisWorkBook
        ThisWorkbook.Worksheets("TempData").UsedRange.Clear
        For ii = 1 To RstRcd.fields.Count
            ThisWorkbook.Worksheets("TempData").Cells(1, ii).Value = RstRcd.fields(ii - 1).Name
        Next ii
        ThisWorkbook.Worksheets("TempData").Cells(2, 1).CopyFromRecordset RstRcd
    Last edited by Rasm; 02-02-2012 at 07:00 AM.
    xl2007 - Windows 7
    xl hates the 255 number

Similar Threads

  1. Replies: 8
    Last Post: 06-08-2013, 01:24 PM
  2. Full Outer Join in MS Access
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-18-2013, 08:42 PM
  3. Deleting Records Using Join
    By MMishra in forum MS-Access Tips And Tricks
    Replies: 0
    Last Post: 04-24-2013, 04:06 PM
  4. VBA Code to create Pivot tables
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 08-05-2012, 02:41 AM
  5. Reading/Saving binary data
    By Rasm in forum Excel Help
    Replies: 3
    Last Post: 02-26-2012, 08:15 PM

Posting Permissions

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