Question

Exporting Word 2007 to Access 2007

Asked by: Paul777

I can't find a good source to explain how to write the code to export a Word 2007 document's content controls data into an Access table. I have working code to export Word 03 into Access 07. Word 07 uses content controls and I can't find the right code to extract the data for a specific control.
I tried this: strTagB = doc.ContentControl("TagB").Result

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-26 at 09:00:34ID24844023
Tags

Office 2007

,

Visual Basic

Topics

Microsoft Office Suite

,

Microsoft Word

,

Microsoft Access Database

Participating Experts
1
Points
500
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Export to Word
    Dear Experts, I need to export a rtf field to word which will have images in it and text. This rtf field should be displayed in a table(this will be next part) This is from notes ui and also, I need to copy images from one rtf to another rtf. Once the image is copied, I ne...
  2. Exporting to Word
    Does anyone have a VBA macro that can export excel sheet(s) to word? And apply formatiing etc.. I was thinking that i would like to export a part of a sheet within a specific row range in one page of a word doc, then stick the next range of rows into the next page in a word ...
  3. Formatting export to word.
    I am using this code to export word, now is there a way to format it? Dim wordobj As Variant Dim add As String Set wordobj = CreateObject("Word.Basic.8") Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Set uidoc = workspace.CurrentDocument Cno=uid...
  4. Best way to export to Word
    Hi ! I'd like to know what would be my best bet when trying to export data from a table and/or query to a Word document. Data exported will actually be an invoice so there will be a fixed header and a dynamic content depending of how much items there will be ? Code snippet a...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: puppydogbuddyPosted on 2009-10-26 at 09:34:40ID: 25664017

Although I currently don't know enough about this subject to help you directly, hopefully this will pont you to a good reference source. Go to the section on content controls and there will be hperlinks to more detail.
                 http://msdn.microsoft.com/en-us/library/dd637847.aspx

 

by: Paul777Posted on 2009-10-26 at 12:52:42ID: 25666044

Thanks but that did not help. I still am unable to find the correct VB code to extract the data entered in a text content control.

 

by: puppydogbuddyPosted on 2009-10-26 at 13:35:22ID: 25666546

Paul,
Ok, try this.  If this doesn't work state what error message you are getting.  Note that I am using ActiveDocument and ContentControls vs ContentControl.   I will try and pursue this for you if no other expert responds:

strTagB = ActiveDocument.ContentControls("TagB").Result


 
   

 

by: Paul777Posted on 2009-10-26 at 14:28:50ID: 25667119

I get a Compile error: Method or data member not found

 

by: puppydogbuddyPosted on 2009-10-26 at 14:59:02ID: 25667371

Try this ...if it doesn't work, please post more of your code so that I can see your code in context, and see how you declared the object and string variables.

strTagB = ActiveDocument.ContentControls.Item("TagB").Result

 

by: Paul777Posted on 2009-10-26 at 16:47:17ID: 25668137

Option Explicit

Sub TransferShipper()
  'Transfer new shipping company record to
  'Shippers table in Northwind database.
  Dim cnn As ADODB.Connection
  Dim strConnection As String
  Dim strSQL As String
  Dim strPath As String
  Dim doc As Word.Document
  Dim strTagA As String
  Dim strTagB As String
  Dim bytContinue As Byte
  Dim lngSuccess As Long
 
  Set doc = ThisDocument
  On Error GoTo ErrHandler
 
  strTagA = ActiveDocument.ContentControls.items("TagA").Results
 
 
 
  'strTagB = doc.ContentControl("TagB").Result
 
  'strTagA = Chr(39) & doc.FormFields("txtTagA").Result & Chr(39)
  'strTagB = Chr(39) & doc.FormFields("txtTagB").Result & Chr(39)

  'Confirm new record.
  bytContinue = MsgBox("Do you want to insert this record?", vbYesNo, "Add Record")
  Debug.Print bytContinue
  'Process input values.
  If bytContinue = vbYes Then
    strSQL = "INSERT INTO Shippers" _
     & "(TagA, TagB) " _
     & "VALUES (" _
     & strTagA & ", " _
     & strTagB & ")"
    Debug.Print strSQL
    'Substitute path and connection string with DSN if available.
    strPath = "C:\Documents and Settings\BigDog\My Documents\Work 09\Sponsored Programs\Nwind.accdb"
   
    'strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" _& "Data Source = " & strPath
     
     
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
     & "Data Source = " & strPath
     
    Debug.Print strConnection
    Set cnn = New ADODB.Connection
    cnn.Open strConnection
    cnn.Execute strSQL, lngSuccess
    cnn.Close
    MsgBox "You inserted " & lngSuccess & " record", _
     vbOKOnly, "Error Added"
    doc.FormFields("txtTagA").TextInput.Clear
    doc.FormFields("txtTagB").TextInput.Clear
  End If
 
  Set doc = Nothing
  Set cnn = Nothing
  Exit Sub
 
ErrHandler:
  MsgBox Err.Number & ": " & Err.Description, _
   vbOKOnly, "Error"
  On Error GoTo 0
  On Error Resume Next
  cnn.Close
  Set doc = Nothing
  Set cnn = Nothing
End Sub

 

by: Paul777Posted on 2009-10-26 at 17:46:05ID: 25668410

Finally, I found a code that works. I now get an error at the "cnn.Execute strSql, lngSuccess" line.

Error: -214721900: Syntax error (missing operator) in query expression 'TabA entry'.

TabA entry is the test data in content control TabA.

-------------------------------


Option Explicit

Sub TransferShipper()
  'Transfer new shipping company record to
  'Shippers table in Northwind database.
  Dim cnn As ADODB.Connection
  Dim strConnection As String
  Dim strSQL As String
  Dim strPath As String
  Dim doc As Word.Document
  Dim strTagA As String
  Dim strTagB As String
  Dim bytContinue As Byte
  Dim lngSuccess As Long
 
  Set doc = ThisDocument
  On Error GoTo ErrHandler
 
  strTagA = ActiveDocument.SelectContentControlsByTitle("TagA").Item(1).Range.Text
  strTagB = ActiveDocument.SelectContentControlsByTitle("TagB").Item(1).Range.Text
   
  'Confirm new record.
  bytContinue = MsgBox("Do you want to insert this record?", vbYesNo, "Add Record")
  Debug.Print bytContinue
  'Process input values.
  If bytContinue = vbYes Then
    strSQL = "INSERT INTO Shippers" _
     & "(TagA, TagB) " _
     & "VALUES (" _
     & strTagA & ", " _
     & strTagB & ")"
    Debug.Print strSQL
    'Substitute path and connection string with DSN if available.
    strPath = "C:\Documents and Settings\BigDog\My Documents\Work 09\Sponsored Programs\Nwind.accdb"
   
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source = " & strPath
     
    Debug.Print strConnection
    Set cnn = New ADODB.Connection
    cnn.Open strConnection
    cnn.Execute strSQL, lngSuccess
    cnn.Close
    MsgBox "You inserted " & lngSuccess & " record", _
     vbOKOnly, "Error Added"
    doc.FormFields("txtTagA").TextInput.Clear
    doc.FormFields("txtTagB").TextInput.Clear
  End If
 
  Set doc = Nothing
  Set cnn = Nothing
  Exit Sub
 
ErrHandler:
  MsgBox Err.Number & ": " & Err.Description, _
   vbOKOnly, "Error"
  On Error GoTo 0
  On Error Resume Next
  cnn.Close
  Set doc = Nothing
  Set cnn = Nothing
End Sub




 

by: puppydogbuddyPosted on 2009-10-26 at 22:05:46ID: 25669270

Using the Execute method on a Connection Object (ADO) object executes whatever sql you pass to it and returns a closed Recordset if there are results and they are from a sql select statement.
                    http://msdn.microsoft.com/en-us/library/ms675023(VS.85).aspx

so change this:       cnn.Execute strSQL, lngSuccess
to this:                Set recordset = cnn.Execute strSQL, lngSuccess

In addition, I think you are closing your connection too soon.  Try moving the cnn.Close statement to the line between the End If and Set doc = Nothing

 

by: Paul777Posted on 2009-10-30 at 13:06:51ID: 25706369

I found a snytax that will extract the data from the content controls.

strDateSubmitted = ActiveDocument.SelectContentControlsByTitle("DateSubmitted").Item(1).Range.Text

If a content control does not have data entered, I get an error stateing that it is missing operator in the query expression. Is there code to entry null values or  create a msgbox relating the missing data?

 

by: puppydogbuddyPosted on 2009-10-30 at 13:24:32ID: 25706505

Try the nz string function which converts nulls to spaces:  

strDateSubmitted = ActiveDocument.SelectContentControlsByTitle(nz("DateSubmitted", "")).Item(1).Range.Text

 

by: Paul777Posted on 2009-10-31 at 05:29:50ID: 25709450

This looks like something I could use. The next issue is when a content control is not filled in, I get a error. How can I code this to allow for empty entries. I can use a If statement to check for content but the argument needs to read If strDateSubmitted = "Click here to enter text." then... to relay the present content.

 

by: puppydogbuddyPosted on 2009-10-31 at 06:09:30ID: 25709605

If nulls and spaces are both a problem, try this way:

If nz("DateSubmitted", "") = "" Then
      MsgBox "You must enter the date submitted."
      Exit Sub
Else
      strDateSubmitted = ActiveDocument.SelectContentControlsByTitle("DateSubmitted").Item(1).Range.Text
End If




 

by: Paul777Posted on 2009-11-02 at 06:41:19ID: 25719701

Looks and works great. I am using this as a marco attached to a .docm word file. The objective is to permit users to fill in some information and after review, be stored in a Access database. On problem now arises when the .docm file is opened on others computers, the maroc seems to disappear.

 

by: puppydogbuddyPosted on 2009-11-02 at 07:26:53ID: 25720201

Are you opening and saving as the correct file type?  see this link:
                       http://office.microsoft.com/en-us/word/HA100445041033.aspx

 

by: Paul777Posted on 2009-11-11 at 11:24:51ID: 31645956

Found alternate solution

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...