How to split large access table to export to excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Angelia Howard
    New Member
    • Sep 2010
    • 4

    How to split large access table to export to excel

    There is no way to narrow down the data with queries.
    I would like to have the vb code to split up an access table into tables of no more than 50000 each to be able to export to excel. The export has to be excel.
  • Mariostg
    Contributor
    • Sep 2010
    • 332

    #2
    This is one way...You can split your big table in as many smaller tables as required with this:

    Function SplitTables()
    Dim rs As New ADODB.Recordset
    Dim cn As New ADODB.Connectio n
    Set cn = CurrentProject. Connection
    Dim rowcount As Integer
    Dim tblcount As Integer
    Dim i As Integer
    sql = "SELECT * INTO tmp_Flush FROM YourBigTable"
    DoCmd.RunSQL sql
    sql = "ALTER TABLE tmp_Flush ADD COLUMN id COUNTER"
    DoCmd.RunSQL sql
    sql = "SELECT count(*) as rowcount from YourBigTable"
    rs.Open sql, cn
    rowcount = rs!rowcount
    rs.Close
    tblcount = rowcount / 50000 + 1
    For i = 1 To tblcount
    sql = "SELECT * into tmp_flush" & i & " FROM tmp_Flush" & _
    " WHERE id<=50000*" & i
    DoCmd.RunSQL sql
    sql = "DELETE * FROM tmp_Flush" & _
    " WHERE id<=50000*" & i
    DoCmd.RunSQL sql
    Next i

    End Function

    Then export those tables into Excel.

    Comment

    • Angelia Howard
      New Member
      • Sep 2010
      • 4

      #3
      I follow everything but "NP_Monitor ing" Where did that table come from?

      Comment

      • Mariostg
        Contributor
        • Sep 2010
        • 332

        #4
        Sorry about that. This would be the name of your large table you want to split.

        Comment

        • Angelia Howard
          New Member
          • Sep 2010
          • 4

          #5
          If I change "NP_Monitor ing" to the name of my table, I get overflow error at "rowcount = rs!rowcount"

          Comment

          • Mariostg
            Contributor
            • Sep 2010
            • 332

            #6
            Ok, that makes sense, Dim rowcount as a long instead :

            Dim rowcount As Long

            Comment

            • Angelia Howard
              New Member
              • Sep 2010
              • 4

              #7
              You are wonderful :) thank you !

              Comment

              Working...