Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Word Document Data into Access 2K3

Status
Not open for further replies.

joebb3

Programmer
Feb 27, 2006
87
US
I have a word document with a checkbox on it. How do I "read" the state of that checkbox in Access 2K3?

I already have the form open and I can read BOOKMARKS just fine. But when I try to read the Checkbox, All I get is something like this "[]".

Here is snippet of my code.

Code:
Set objword = CreateObject("word.application")

        With objword
            objword.Visible = False
            objword.Documents.Open (ContactForm)

            objword.ActiveDocument.Bookmarks("first").Select
            Me!first = objword.Selection.Text
            objword.ActiveDocument.Bookmarks("last").Select
            Me!last = objword.Selection.Text
            
' *******************************************         
            objword.ActiveDocument.Bookmarks("RBLRecommendedY").Select
            RBLRecommendedY = objword.Selection.Value
            objword.ActiveDocument.Bookmarks("RBLRecommendedN").Select
            RBLRecommendedN = objword.Selection.Value
            If RBLRecommendedY = True Then
                Me!RBLRecommended = "Yes"
            End If
            If RBLRecommendedN = True Then
                Me!RBLRecommended = "No"
            End If
'*************************************************
            
        End With
        objword.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
        objword.Quit
    Else
        DoCmd.Close acForm, "ContactInfoImportfrm"
        Exit Sub
    End If

The top part works fine. First and last populate on my Access form.

The area contained in the "****" is my failed attempt at passing the checkbox state to my Access form.

I don't like the Word Combo Box (it looks terrible) so that isn't an option and the "Web Control" Combo box trips the Macro Warning, so I don't want to use that either.

The BEST way for me to accomplish what I need is with a Checkbox on the Word form and read the state of that box from Access.

Thanx!
Joe

 
Nevermind... I finally found it. I had been looking for a WHILE when I posted.

Here's what works:

Code:
            RBLRecommendedY = objword.ActiveDocument.FormFields("RBLRecommendedY").CheckBox.Value
            RBLRecommendedN = objword.ActiveDocument.FormFields("RBLRecommendedN").CheckBox.Value
            If RBLRecommendedY = True Then
                Me!RBLRecommended = "Yes"
            End If
            If RBLRecommendedN = True Then
                Me!RBLRecommended = "No"
            End If

Joe
 
Joeb, sorry to intrude on your thread but is this to import data on a wrod form to access table ? I am looking for a way to do that right now; many thanks.


"No-one got everything done by Friday except Robinson Crusoe...
 
Sure is... It takes bookmarked text fields and puts them on an unbound form.

Then you can save the unbound fields wherever you want.
 
Thanks Joe, hadn't seen that before on Tech Tips; I have been looking for Word-to-Access VB code for a while.

"No-one got everything done by Friday except Robinson Crusoe...
 
Anyone else following this and interested in the background can look at:


"Visual Basic Mail Merge using MS Word Bookmarks"

++++++++++++
Tech Tips guys, I have pasted in their free tutorial; hope it doesn't present any copyright problems ?
++++++++++++


To accomplish this task you'll need to create a Word template document with bookmarks inserted in the database field locations. These bookmarks will represent the variable part of the document.

Next create an Access form with a button called Enveloppe. And, create an on click event as shown below. You'll need to customized the PathDocu line to match you particular setup.

Private Sub Enveloppe_Click()

Dim MyWord As Word.Application
Dim PathDocu As String

If Me.NomPers <> "" And Me.Prénom <> "" Then
Set MyWord = New Word.Application
PathDocu = "C:\Documents and Settings\BENOIT\Mes documents\Word\IFFC\BaseDeDonnée\Documents\"

With MyWord
.Documents.Open (PathDocu & "Env22x10.doc")
'.ActiveDocument.Bookmarks("date").Range.Text = & _
Format(Date, "dd mmmm yyyy")
.ActiveDocument.Bookmarks("nom").Range.Text = Me.NomPers
.ActiveDocument.Bookmarks("prénom").Range.Text = Me.Prénom
If Me.Adresse <> "" Then
MyWord.ActiveDocument.Bookmarks("adresse").Range.Text = & _
Me.Adresse
If Me.Adresse2 <> "" Then
MyWord.ActiveDocument.Bookmarks("adresse2").Range.Text & _
= Me.Adresse2
If Me.CodePostal <> "" Then
MyWord.ActiveDocument.Bookmarks("codepostal").Range.Text &_
= Me.CodePostal
If Me.Ville <> "" Then MyWord.ActiveDocument.Bookmarks("ville").Range.Text =Me.Ville
If Me.Pays <> "" Then MyWord.ActiveDocument.Bookmarks("pays").Range.Text = Me.Pays
' si vous désirez utiliser plusieurs fois les mêmes données, vous devez
' créer des signets différents
.Visible = True
End With
DoEvents
Set MyWord = Nothing
End If
On Error GoTo Err_Enveloppe_Click

Exit_Enveloppe_Click:
Exit Sub

Err_Enveloppe_Click:
MsgBox Err.Description
Resume Exit_Enveloppe_Click

End Sub


Contributed by Benoit Mann
++++++++++++

"No-one got everything done by Friday except Robinson Crusoe...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top