Results 1 to 8 of 8
  1. #1
    dnme is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    5

    Export to Excel from unbound subform datasheet?

    Hi,

    I am wondering if anyone can help me here. I have an Access 2003 adp project. In it I have a search form/subform. The form provides controls for the user to select search criteria, the subform is a datasheet that displays the search results. I have designed this as an unbound subform, I set it's recordset property in VBA code.

    However, I am finding that I cannot export this datasheet to excel, nor can I print it. These functions only seem to work for bound forms. My subform datasheet has the columns ordered in a certain way (across the top) and some columns are hidden so I would really like to be able to export it (DoCmd.OutputTo) rather than copy trhe underlying recordset to excel which outputs all fields in wronmg order etc.

    So is there a way to export and print unbound forms / datasheets? I'm really stumped on this.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Open Excel workbook and then read value of control on form and save to cell of worksheet - one field and record at a time.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dnme is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    5
    Quote Originally Posted by June7 View Post
    Open Excel workbook and then read value of control on form and save to cell of worksheet - one field and record at a time.
    Many thanks for the reply.

    But I'm wondering if this is workable say if I have 50000+ results in my recordset returned? Could you provide sample code as to how I would iterate through each column on a datasheet?

    Many thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Don't have anything specific to your situation. Start with a review of this http://forums.aspfree.com/microsoft-...el-414974.html

    Instead of a recordset you could read each form control by name, save to cell of worksheet, move to next record of form and repeat. What you should get out of the links is how to open a workbook object and how to use loop code to change cell reference. I don't know how long 50,000 records would take with this method, maybe quite a while. Alternative is to build a query that replicates the dataset of the subform and export the query. You want the hidden fields data to export as well?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    dnme is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    5
    No I do not want to export hidden fields, It works great when the subform datasheet is bound. I can then use DoCmd.OutputTo, but once I unbind the subform, I am stumped. Thanks for your help anyway.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    It is possible to do export by method I describe but 50000 records could be very slow. I just don't know if 'slow' would be 10 minutes or 10 hours. You don't want the hidden data then ignore those textboxes.

    Why unbound form? Doesn't it become bound by setting the RecordSource property in VBA? How do you populate the controls?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    dnme is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    5
    Its unbound for a number of reasons, firstly the underlying SQL Server has a stored proc whick takes many optional parameters, this is the search part. I have now included an output parameter in it which gives me back the record count (this is the accurate way to do this as subform recordset counts are not reliable). So I need to consume an output param, therefore I cannot use form binding, rather I need to code my sql string and parameters into a command object, execute that and then I can access the returned output parameter. I also want to clear the subform (no records) when the user presses the clear search button etc etc.

  8. #8
    Norbert is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    1
    Hi,
    I created an MS Access add-in called 'A2EE.mda' (which stands for Access To Excel Exporter) and it is to be downloaded on:
    <old invalid link removed>
    It is intended right for exporting data from subforms to Excel sheets.
    I wonder if this add-in can solve your dilemma?
    Will you try and let us know?
    BR
    Norbert
    Last edited by pbaldy; 12-15-2014 at 03:23 PM. Reason: removed link which no longer worked

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

Similar Threads

  1. Get Export File name from Unbound Text Box
    By FinChase in forum Import/Export Data
    Replies: 1
    Last Post: 01-11-2012, 11:09 AM
  2. Replies: 3
    Last Post: 10-07-2011, 07:49 AM
  3. Export table to excel using excel template
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 1
    Last Post: 06-27-2011, 02:10 AM
  4. Exporting Datasheet to Excel
    By evhfan2000 in forum Access
    Replies: 1
    Last Post: 06-16-2011, 05:36 PM
  5. Show Recordset in unbound subform
    By vgarzon in forum Forms
    Replies: 4
    Last Post: 03-02-2011, 04:11 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