Solved

Exporting Access Memo fields to Excel

Posted on 2011-02-22
3
550 Views
Last Modified: 2012-05-11
I'm trying to export an Access query to Excel, but the memo fields get truncated.

My initial thought here is to programatically divide up this Memo data (up to 2000 characters) into smaller chunks and export it to seperate rows.

Before I do that, are there any Excel tricks I am overlooking to avoid this?
0
Comment
Question by:mbizup
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
ID: 34953322
Set a variable of Variant type to the Memo field, then write it to a cell using Range.Value:
Public Sub ExportMemoField()

   Dim strCurrentPath As String
   Dim wkb As Excel.Workbook
   Dim appExcel As New Excel.Application
   Dim rst As DAO.Recordset
   Dim varMemo As Variant
   Dim strWorkbook As String
   Dim sht As Excel.Worksheet
   Dim strRange As String
   Dim rng As Excel.Range
   
   strCurrentPath = Application.CurrentProject.Path & "\"
   Set wkb = appExcel.Workbooks.Add
   appExcel.Visible = True
   'strWorkbook = strCurrentPath & "Memo Field.xls"
   'wkb.SaveAs FileName:=strWorkbook
   Set sht = wkb.Sheets(1)
   strRange = "A1"
   Set rng = sht.Range(strRange)
   Set rst = CurrentDb.OpenRecordset("tblContacts")
   
   Do While Not rst.EOF
      varMemo = rst![Notes]
      If IsNull(varMemo) = False Then
         rng.Value = CStr(varMemo)
         Set rng = appExcel.ActiveCell.Offset(rowoffset:=1)
      End If
      rst.MoveNext
   Loop
      
   Set appExcel = Nothing
   
End Sub

Open in new window

0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34953338
You may need to redo your code to do the entire export in code, rather than exporting the whole query.
0
 
LVL 61

Author Comment

by:mbizup
ID: 34953469
Helen,

Thanks - that works.

Not as elegant, but I also found that if I change my query to a make-table query and export the table instead of the query, the truncation does not occur.

no idea why...

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now