Using bookmarks in word, what other options can be used.

RichardP1978

Registered User.
Local time
Today, 23:09
Joined
Nov 14, 2006
Messages
89
OK,

Tried doing a search, but all I found was what I can already do.

I use the following code to make access open word up, fill in a blank. What I would like to do is for access to open word, fill in the blank, print the word document out, and close word without confirming the need to save the file, the answer to this is no as the document does not need saving.

I have not used a report in access to do what I want, as there is fairly complex laying out required, (further down the line with another document) but being able to do this silently with this document would be good. Plus, when the layout has to change, I only edit a word document, not play around with a access report and then distribute it amongst all users.

So what I am asking, what other options can I put in code?

Thanks in advance.

Here is the code I use.

Set objWord = CreateObject("Word.Application")
objWord.Visible = True 'True is visible

objWord.Documents.Add ("F:\ClientDatabase\Templates\Tobaccorecordfor.dot")

objWord.activedocument.bookmarks("Name").Select
objWord.selection.Text = Forms![frmclientmain]![FirstName] & " " & Forms![frmclientmain]![Surname]
 
try using this:
Code:
...first part cut for space

objWord.activedocument.bookmarks("Name").Result = Forms![frmclientmain]![FirstName] & " " & Forms![frmclientmain]![Surname]
 
You can just disable the Alerts in Word (equivalent of SetWarnings=False in Access) using this:

Code:
Set objWord = CreateObject("Word.Application")
objWord.Visible = True 'True is visible
objWord.DisplayAlerts = wdAlertsNone
.
.
<your other code here>

~Moniker
 
OK, thanks for that, how could I get word to print, preferably to a specific printer, and then close so the user does nothing.
 
Rather than typing a lot of sample code here perhaps it would be more useful to nudge you towards using help in Word's code editor.

Allo fo the information you seek is there, Its quite clear and you may be surprised at just how much you can achieve with Word.
 
Here's a quick typeup
Code:
Sub wordtesting()
    
    Dim w                   As Word.Application ' or object
    Dim doc                 As Word.Document    ' or object
    Dim fClose              As Boolean
    
    On Error Resume Next
    Set w = GetObject(, "word.application")
    If Err.Number <> 0 Then
        Err.Clear
        ' not open, create an instance
        Set w = CreateObject("word.application")
        If Err.Number <> 0 Then
            ' word installed???
            Set w = Nothing
            Exit Sub
        End If
        fClose = True
    End If
    
    Set doc = w.Documents.Add("c:\sometemplate.dot")
    If doc.Bookmarks.Exists("test") Then
        doc.Bookmarks("test").Range.Text = "Some text or other"
    End If
    
    doc.PrintOut
    doc.Close False
    Set doc = Nothing
    If fClose Then w.Quit
    Set w = Nothing    
End Sub
Note that if Word is already open, and there's a dialog box open, the above might barf.

Printing to a specific printer, I've never done, check out for instance http://www.gmayor.com/fax_from_word.htm
 
Thanks guys, that give me some food for thought there. I wasnt aware that word itself had a code editor.

Roy,

Thanks for that, it is helpful, I also like the idea of it checking to see if word is open first.

Thanks.
 

Users who are viewing this thread

Back
Top Bottom