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.
Main Topics
Browse All TopicsI 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")
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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.ContentCont
'strTagB = doc.ContentControl("TagB")
'strTagA = Chr(39) & doc.FormFields("txtTagA").
'strTagB = Chr(39) & doc.FormFields("txtTagB").
'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.OL
strConnection = "Provider=Microsoft.ACE.OL
& "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").
doc.FormFields("txtTagB").
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
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.SelectConte
strTagB = ActiveDocument.SelectConte
'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.OL
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").
doc.FormFields("txtTagB").
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
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/
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
I found a snytax that will extract the data from the content controls.
strDateSubmitted = ActiveDocument.SelectConte
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?
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.
Are you opening and saving as the correct file type? see this link:
http://office.microsoft.co
Business Accounts
Answer for Membership
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. en-us/libr ary/dd6378 47.aspx
http://msdn.microsoft.com/