Export Yes/No Value to Word Checkbox

bonekrusher

Registered User.
Local time
Today, 02:15
Joined
Nov 19, 2005
Messages
266
Hi all,

Does anyone know how to Export Yes/No Value to Word Checkbox? This is what I have so far.


Code:
Dim path As String
Dim objWord As Object
pathx = CurrentProject.path & "\file.dot"
Dim dtnow As String
DoCmd.SetWarnings False

   
         Set objWord = CreateObject("Word.Application")
         objWord.Visible = False 'True is visible
        
       'path and name of the template your are using.
         objWord.Documents.Add (pathx)
                          
         If Me.FAA145 = -1 Then
         objWord.ActiveDocument.Bookmarks("check1").Select
            objWord.Selection.CheckBox = 1
         End If
 
Solution

Incase anyone wanted to know..here is the solution:

Code:
 Dim path As String
Dim objWord As Object
path = CurrentProject.path & "\file.dot"
Dim dtnow As String
DoCmd.SetWarnings False

   
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = False 'True is visible
        
    'path and name of the template your are using.
    objWord.Documents.Add (pathx)
                          
    If Me.FAA145 = -1 Then
    [COLOR="Red"]objWord.ActiveDocument.FormFields("Check1").CheckBox.Value = True[/COLOR]
    End If
 
Did not work for me ...

... when I try that I get

Runtime error 5941. The requested member of the collection does not exist.

Any further thoughts...
 
nope

I have that selected ..... as I tated in another post, I am successfully filling in bookmarks - just cannot get a checkbox to work.

Thanks for all your help,
 
break down your code and post it. I read you other post. POst your code which only applies to the Checkboxes.. We'll take a look at it.

Whe replying, use the #Code/#code - its much easier to view.
 
Thank you so much Bonekrusher. At this point, I am trying to get it to check the chkUrgent checkbox no matter what. Once I get this command to work I can get the true/false logic in place. Here is the code for that module ....

#####CODE #######

Public Sub CreateFax2(recSubmittal As DAO.Recordset, strTitle As String, strFirst As String, strLast As String, strSender As String, strPhone As String, strFile As String, strSubject As String, strFax As String, strPages As String, strComments As String, strUrgent As String, strReview As String, strReply As String)
Dim strName, strBkmk, strDate As String
Dim varText As Variant
Dim strFolder, strDir, strFileName, strSubDir As String
Set m_objWord = New Word.Application
Set m_objDoc = m_objWord.Documents.Add(m_strDIR & m_strTEMPLATE)

m_objWord.Visible = True

strName = strTitle & (" ") & strFirst & (" ") & strLast
strDate = Date$
InsertTextAtBookmark "name", strName
InsertTextAtBookmark "date", strDate
InsertTextAtBookmark "fax", strFax
InsertTextAtBookmark "phone", strPhone
InsertTextAtBookmark "file", strFile
InsertTextAtBookmark "pages", strPages
InsertTextAtBookmark "sender", strSender
InsertTextAtBookmark "reference", strSubject
InsertTextAtBookmark "comments", strComments
InsertTextAtBookmark "project_number", recSubmittal(1)
InsertTextAtBookmark "project_name", recSubmittal(2)
m_objWord.ActiveDocument.FormFields("chkUrgent").CheckBox.Value = True
'InsertTextAtBookmark "forreview", strReview
'InsertTextAtBookmark "pleasereply", strReply
strFolder = "20" & Left(recSubmittal(1), 2)
strDir = recSubmittal(1)
strSubDir = strFile
strFileName = "fax-" & strName & "-" & strSubject & ".doc"
m_objDoc.SaveAs ("S:\JECProjects\" & strFolder & "\" & strDir & "\" & strSubDir & "\" & strFileName)
End Sub

Private Sub InsertTextAtBookmark(strBkmk As String, varText As Variant)
'This finds the bookmarks in the Word template to place the data.
m_objDoc.Bookmarks(strBkmk).Select
m_objWord.Selection.Text = varText & ""
End Sub

####### END CODE #######

All the inserts work. The only thing that does not work is the checkbox.

Thanks again for all your help
 
I am not 100% but this line uses "m_objWord.ActiveDocument.FormFields("chkUrgent").C heckBox.Value = True" uses activedocument and I thinkyou code uses a new document.... I am not sure if that is the issue
 
Actually, I open the document at the top of the code. Then I work with the document filling it in. I use the ActiveDocument while filling in all my bookmarks so I think it should work with this.
 
sorry bonekrusher, I was msitaken. I am not using the activedocument in any other part of my code. Question then becomes, how should this be written if not with the activedocument?
 
not sure if this will work, try

m_objWord.Document.FormFields("chkUrgent").C heckBox.Value = True
 
That did not work either --- I am beginning to think that this is impossible, except I know people do this.
 
ok, I tried to insert another checkbox to my template and I am recieving the same error. This leads me to believe the original code is correct and the template is not correct. I will let you know in a few minutes....
 
ok...I think I found the solution. Make your checkboxes from the FORMS toolbar. After you insert it, check the name of the bookmark. It will start with Check1, check2 etc...

Let me know how it goes.
 
Ok, i think I got it. Using the original code in VBA should work. In your work template make your checkboxes from the FORMS toolbar. It will name each bookmark as check1, check2 etc...

let me know how it goes.
 
Wow, maybe this will be progress - I hope. I had not thought to check the validity of the template. I will do some research also
 
It worked!!! It worked!!! How awesome is that! You are the best bonekrusher. Thank you so very much.
 

Users who are viewing this thread

Back
Top Bottom