473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,387 developers and data experts.

Exporting filtered access Datasheet to Excel spreadsheet - No truncation

Jerry Maiapu
259 100+
I have been working on a project and one of the things my client wanted was to have a nice formatted duplicate excel spreadsheet of a manually filtered sub form datasheet with all records exported including memo.

I at first struggled but have come up with the following code which I wish to share as I know that people will need it for their database knowledge and projects.

One of the main issues faced currently on exporting is “truncation” of memo fields from access to excel.
However, this will not be experience with my code, because an instance of excel application object is created and the data on the datasheet is basically copied and pasted on the spreadsheet.

I have experimented with 500 words (approx. more 2000 characters in memo field) and all exported and intact in cell.

Hope you will love using my code.

Note: I have tried with “DoCmd.TransferSpreadsheet” and “DoCmd.OutputTo” but has caused a nightmare for me.

But there are different experiences and people might work around these 2 procedures, did not work well for me.
Happy programming!

Cheers!

Jerry



Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. '*******************************************
  3. 'Author: Jerry Maiapu
  4. 'email: jmaiapu@atlantisgoose.com
  5. 'Please do not remove the author's name
  6. 'This is code basically copies filtered records from a subform dataseet to an excel spreadsheet
  7. 'There are a few basic formating applied once exported to Excel
  8. 'Decided to share this as I have seen many people asked questions in reagrds to access to excel data export
  9. 'Note that with this code, memo fields will not be trunculated..
  10. Option Explicit
  11. Private Sub export_Click()
  12. Me.usn_subform.SetFocus                'line 1: Selects the subform
  13. Me.usn_subform!Item.SetFocus           'Line 2: sets the focus in the first field/record in the subform
  14. DoCmd.RunCommand acCmdSelectAllRecords  'Select all the records-ie including filtred records
  15. DoCmd.RunCommand acCmdCopy              'Copy the selected record
  16. Dim xlapp As Object
  17.  
  18. Set xlapp = CreateObject("Excel.Application") 'create an excel application object
  19. With xlapp
  20. .Workbooks.Add 'add new workbook in the excel
  21. .ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False ' Line 10
  22. 'Line 10: paste the copied records,not as a link please
  23. .Cells.Select 'now select all cells in excel
  24. .Cells.Entirecolumn.WrapText = True 'wrap text in all cells
  25. .columns("N:N").ColumnWidth = 60
  26. .columns("M:M").ColumnWidth = 90
  27. .columns("O:O").ColumnWidth = 90
  28. .columns("A:L").ColumnWidth = 18
  29. .columns("A:A").ColumnWidth = 8
  30. .columns("G:I").ColumnWidth = 10
  31. .columns("R:R").ColumnWidth = 13
  32. 'the above does this: More spaces needed in columns N&M  while less space needed in A & G to I
  33.  
  34. .Cells.rows.AutoFit 'applying auto fit feature for rows
  35. .selection.AutoFilter 'Apply autor filter
  36.  
  37. '***************************************************************************************
  38. 'Now loop through the rows starting from row 1 to 19 which is A1 to S1 and apply formating as below
  39. Dim i As Integer
  40. For i = 1 To 19
  41. .Cells(1, i).Font.Bold = True
  42. .Cells(1, i).Font.ColorIndex = 3
  43. .Cells(1, i).Interior.ColorIndex = 37
  44.  
  45. Next 'end of loop
  46. '****************************************************************************************
  47.  
  48. .worksheets(1).Cells(2, 2).Activate ' make cell B2 as the active cell
  49. .activewindow.freezepanes = True 'Now freezepanes from the active cell B2
  50. .Visible = True
  51. .range("a1").Select 'If for some reason if other cells are selected please select A1 as am now done.
  52.  
  53. End With
  54. export_Click_Exit:
  55. Exit Sub
  56. export_Click_Err:
  57. MsgBox Error$
  58. Resume export_Click_Exit
  59. End Sub
You just need to create a button on the main/parent form (in this case is export) and simply copy and paste the code above.

Remember to change the subform name, the subform field name and the cmd button name as per underlined in code.
Jul 14 '12 #1
4 37065
nazero
2
I have searched online for a while for this piece of information and never found a solution for one of my projects. Thank you Mr. for this helpful article.

It did helped me so much.
Apr 25 '14 #2
lemon
1
Exporting custom filtered query and datasheet subform was one of the frequently asked questions on the forums and I appreciate your valuable input in sharing this.

I have seen a lot of hints and articles on this particular matter of subject (truncation) but never really found one solution because i had to put pieces together to solve the puzzle.

This is indeed is a helpful article and code.

Thank you so much for sharing Sir.
Apr 25 '14 #3
nazero
2
I am definitely sharing this link on many of the forums.

10Q
Apr 25 '14 #4
This code works great. However, I need to add this sheet to a template and I am having a hard time trying to modify it to copy to a worksheet in an existing workbook file. I was hoping you could help me.
Mar 23 '17 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kaos99 | last post by:
Is there anyway of colour coding values in a report for given criteria and then exporting this formating into an Excel spreadsheet. What I have is a table full of details that are being changed...
2
by: cjay85 | last post by:
I wish to direct reports that I have created in Access to Excel enabling me to produce a graphical output from Excel. The report is a simple query regarding responses to a letter mailing. There...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: Slicemahn | last post by:
Hi Everyone! I have a spreadsheet in which I would need to update daily and have the new record added to a table in Access. Any ideas on writing code to update the d-base with the new data? ...
2
by: nofear | last post by:
I used to export my reports as snapshot but now I have to export them to Excel When I export my report to a Excel Spreadsheet the report header and footer are not included Only the data gets...
7
by: tasmontique | last post by:
Hi All, I have finally succeeded in exporting to a preformated excel spreadsheet. I have one tiny setback. One of the sheets I am exporting to must be password protected. When I do this and...
2
by: atlbearcat | last post by:
Here's one that's been bugging me for about a week now... I have a form that allows users to filter records, simple enough. But I want to give them the option to export the filtered records to...
1
by: stingaway | last post by:
Have an end user who prefers to see everything in Excel, neatly grouped. I know how to export to Excel - but is there a way to export a query from Access directly into Excel with groupings...
14
by: fkbodley | last post by:
I am trying to upload a filtered form to excel. Using code someone posted to me I tried to make this work. But like all great code for a newbee.. IT DOSENT WORK! Can some one help me out. Code:...
4
by: Dave Smith | last post by:
I’ve read a lot of different article on the internet about being able to export a table from MS Access to Ms Excel. Problem I’m having is that I don’t know which one would work best for me, so I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.