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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Check Box to Populate Word Check Box

Status
Not open for further replies.

jpkeller55

Technical User
Apr 11, 2003
131
0
0
US
I have the following code that is populating data to a word document quite nicely. Now I need to have a checkbox from the Access Form populate its value to a checkbox on the Word document.
Code:
Public Function CreateWordLetter(strDocPath As String)
   
   If IsNull(strDocPath) Or strDocPath = "" Then
      Exit Function
   End If

   Dim objWord As Object
   Dim PrintResponse
   'Set dbs = CurrentDb
      
   Set objWord = CreateObject("Word.Application")
   
   With objWord
       .Visible = True
       .Documents.Open (strDocPath)
   End With

   If objWord.ActiveDocument.Bookmarks.exists("AgNm") = True Then
     objWord.ActiveDocument.Bookmarks("AgNm").Select
     objWord.Selection.TypeText Forms!NrsContFrm!NAname & ""
   End If
    If objWord.ActiveDocument.Bookmarks.exists("Attn") = True Then
     objWord.ActiveDocument.Bookmarks("Attn").Select
     objWord.Selection.TypeText Forms!NrsContFrm!NAcontact & ""
   If objWord.ActiveDocument.Bookmarks.exists("Dt") = True Then
  objWord.ActiveDocument.Bookmarks("Dt").Select
  If IsDate(Forms!NrsContFrm!TodayDate) Then
     objWord.Selection.TypeText Format(Forms!NrsContFrm!TodayDate, "mmmm d, yyyy")
  Else
     objWord.Selection.TypeText ""
  End If
End If
         
   Set objWord = Nothing

End Function
I have tried inserting this line to the code but what gets populated to the Word document is a 0 or -1.
Code:
If objWord.ActiveDocument.Bookmarks.exists("check4") = True Then
     objWord.ActiveDocument.Bookmarks("Check4").Select
     objWord.Selection.TypeText Forms!NrsContFrm!Check1 & ""
   End If
How do I need to format the code for the check box value in word to be either checked or not checked based on the value of the Access check box? Thanks, JK

 
First, I'd recommend being a bit more explicit, and declare and instantiate a document object

[tt]dim oDoc as object ' word.document
set oDoc = oWord.Documents.Open(strDocPath)[/tt]

then refer through this in stead of .Activedocument

Try:

[tt]If oDoc.Bookmarks.exists("check4") Then
' dunno if this is necessary, though
If oDoc.FormFields("check5").Type = 71 Then
' 71 -> wdFieldFormCheckBox
oDoc.FormFields("check5").CheckBox.Value = Forms!NrsContFrm!Check1
End If
End If[/tt]

Remember to release the document object prior to releasing the word application object

Roy-Vidar
 
Thanks RV...I will see if I can figure out how to incorporate what you have suggested. Thanks, JK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top