Results 1 to 4 of 4
  1. #1
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53

    export total number of results to excel


    Does anyone have any suggestions on how to export the total number of rows returned from a query to a specific cell in excel? I am running an access Query and would like the total number returned populate a cell in an excel worksheet. I have tried the Importexportspreadsheet but it does not allow enough flexability for specific cell and data.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    you have to take control of a new instance of excel , then go directly to the cell....
    NOTE: YOU MUST ADD EXCEL TO THE REFERENCES. vbe menu, tools, references, checkmark Excel

    Code:
    Public Sub ControlXL(byval pvXLfile)
    Dim r As Long
    Dim xl As Excel.Application
    
    
    Set xl = CreateObject("excel.application")
    With xl
        .Visible = True
        .Workbooks.Open pvXLfile
        .Range("C21").value = "abc"
        .activeworkbook.save
    End With
    Set xl = Nothing
    End Sub

  3. #3
    xopherira is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Indiana
    Posts
    53
    That looks pretty close but where does the query fit in?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    i thought you'd know. this code is for 1 value.
    if you want to paste the query

    use COPYFROMRECORDSET

    Code:
    set rst = currentdb.openrecordset("qsMyQuery")
    
    
    With xl
        .Visible = True
        .Workbooks.Open pvXLfile
        .Range("C21").value = "abc"
       
        .Activesheet.Range("j21").CopyFromRecordset rst
    end with

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 20
    Last Post: 03-13-2014, 12:50 PM
  2. Replies: 3
    Last Post: 01-07-2014, 03:39 PM
  3. Replies: 2
    Last Post: 10-20-2013, 02:11 PM
  4. Replies: 1
    Last Post: 04-30-2012, 05:10 PM
  5. Export Filtered Results to Excel Tabs
    By opod in forum Programming
    Replies: 1
    Last Post: 08-03-2011, 01:33 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
  •  
Other Forums: Microsoft Office Forums