Export current record to word

G

Guest

I have read how to view just current record in report. But I would like to
create a button in the form that would export my current record from the form
to MS Word, using report template.
In addition, I can not figure out how to avoid displaying fieds with no
information in my report/word file. In another words I would like to include
only fields that I have inputed info in.
Thanks
 
G

Guest

Create A word document, insert book marks where you want the value from
access should be insert, and then run this code

Public Sub PrintToWord()
Dim wd As Word.Application
Dim myDoc As Word.Document

Set wd = New Word.Application
wd.Documents.Add DOTpath & reportName & ".dot" ' The name and path
Set myDoc = wd.ActiveDocument
With wd.Selection
.GoTo wdGoToBookmark, Name:=BookMarkName ' The name of the book
mark
.Font.Bold = True ' You can choose if bold
.Font.Underline = False ' or underline
.TypeText Text:=ValueToInsertInTheBookMark ' insert values
End With
wd.Visible = True

End Sub
 
G

Guest

This sound great. Is there any way to do a little bit more detailed
explanation.
In word - do I create fields or just plain text with subtitiles
In access. Do I create a standard report
Where I should insert this code.

I am sorry for damn questions, but this is a little over my head.
Great thanks
 
G

Guest

I'll to give you an example that you can try
1. create a document in word called testDoc.Doc and insert this line
Trying to pass parameters to word from access ( in the end of this line
insert a book mark name MyFirstBookMark, using insert -> book mark)
2. Save the document on c:\
3. create a form in access with a text box and a button.
4. On the onclick event of the button insert the code
Dim wd As Word.Application
Dim myDoc As Word.Document

Set wd = New Word.Application
wd.Documents.Add "c:\testDoc.Doc"
Set myDoc = wd.ActiveDocument
With wd.Selection
.GoTo wdGoToBookmark, Name:="MyFirstBookMark" ' The name of the
book mark
.Font.Bold = True ' You can choose if bold
.Font.Underline = False ' or underline
.TypeText Text:= me.textFieldName ' insert values In it
End With
wd.Visible = True

If that works then create your documents with all the bookmarks you want to
send
 
G

Guest

I had set up everything like you wrote, but clicking on button
produces compile error
User-defined type not defined
Here is what I got for that button





Private Sub Command4_Click()
Dim wd As Word.Application
Dim myDoc As Word.Document

Set wd = New Word.Application
wd.Documents.Add "c:\testDoc.Doc"
Set myDoc = wd.ActiveDocument
With wd.Selection
.GoTo wdGoToBookmark, Name:="MyFirstBookMark" ' The name of the
book mark
.Font.Bold = True ' You can choose if bold
.Font.Underline = False ' or underline
.TypeText Text:=Me.textFieldName ' insert values In it
End With
wd.Visible = True

End Sub

and wd As Word.Application gets highlighted.

What do I need to do
 
G

Guest

Create reference to word
While in code, select tools reference, add from the list microsoft word
 
G

Guest

Any time, about the other question you asked "autotext in the forms" you got
an answer from Doug Steele.
 
G

Guest

I got a followup guestion. Is it possible to place the whole content (30-40
field) of the details section of the report in one bookmark. I have setup
shrinking fields and I do not want to export different fields to different
bookmarks because it will produce too much empty space. In addition, I would
like to set up header and footer in word document, but having problems with
this function in access.
 
G

Guest

You can join few fields together, when you send the value to the bookmark you
can write
bokmark=me.field1 & " " & me.field2 & " " & me.field3 .....
 
G

Guest

Can I format text this way. I will need to export labels and text fields.
Each field will need to start from new line. Or is there any better way of
doing it. My main problem that I want to use word template with header and
footer and exporting from report does something strange with my report footer
and header.
Thanks
 
G

Guest

In your post "autotext in the forms" I gave you an example how to start text
in a new line, not long ago I post the aswer for your question there.

So you can try this
dim MyText as string
MyText = "A Lable:" & Me.MyField1 & vbCrLf & _
"A lable2:" & Me.MyField2 & vbCrLf & _
"A lable3:" & Me.MyField3 & vbCrLf & _
"A lable4:" & Me.MyField4 & " " & Me.MyField5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top