Solved

Exporting Access Memo fields to Excel

Posted on 2011-02-22
3
556 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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