473,545 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access table OutPutTo Word bookmark

Gday,

I have a set of Access 2000 tables that I would like to export into a
MS Word 2000 template at specific bookmark locations that I've set up.

Would anyone know the code to achieve something like this? I've heard
about using the OutPutTo method, but I'm not sure if it can output to a
specific bookmark location.

Any thoughts?

Thanks,
Keith

Jan 12 '06 #1
2 4206
On 12 Jan 2006 00:23:29 -0800, fo******@gmail. com wrote:
Gday,

I have a set of Access 2000 tables that I would like to export into a
MS Word 2000 template at specific bookmark locations that I've set up.

Would anyone know the code to achieve something like this? I've heard
about using the OutPutTo method, but I'm not sure if it can output to a
specific bookmark location.

I have just made it, using automatation. Following sub opens a new word
document file, based on template with the appropiate bookmarks and other
fixed stuf.

<vba_code>

Enum wordCommand
gotoBMIns
indent
indentBack
gotoBM
ins
insFootNote
End Enum

'1 arg: array of word commands and their content
'2 arg: destination file for new word document
'3 arg: template source
Public Function MergetoWord(mer geContent, _
Optional destFile$ =
"C:\usr\benny\w ork\jobs\kontak t\Systemmatiser et\ans.doc", _
Optional Skabelon$ = "E:\Program Files\Microsoft
Office\Skabelon er\jobans.dot")
' This method creates a new document in MS Word 97 using Automation.
On Error Resume Next
Dim rsCust As Recordset, cI%, cBound%, indent As New Stack
Dim WordObj As Word.Applicatio n

indent.push 0
DoCmd.Hourglass True

Set WordObj = GetObject(, "Word.Applicati on.8")
If err.Number <> 0 Then
Set WordObj = CreateObject("W ord.Application .8")
End If

WordObj.Visible = True

WordObj.Documen ts.Add Template:=Skabe lon, NewTemplate:=Fa lse

cBound = UBound(mergeCon tent)
cI = 0
Do
Select Case mergeContent(cI )
Case wordCommand.got oBMIns:
WordObj.Selecti on.Goto What:=wdGoToBoo kmark,
Name:=mergeCont ent(cI + 1)
WordObj.Selecti on.TypeText mergeContent(cI + 2)
cI = cI + 3
Case wordCommand.ind ent
indent.push mergeContent(cI + 1)
WordObj.Selecti on.ParagraphFor mat.LeftIndent =
WordObj.Centime tersToPoints(in dent.pop)
cI = cI + 2
Case wordCommand.ind entBack
indent.pop
WordObj.Selecti on.ParagraphFor mat.LeftIndent =
WordObj.Centime tersToPoints(in dent.pop)
cI = cI + 1
Case wordCommand.got oBM
WordObj.Selecti on.Goto What:=wdGoToBoo kmark,
Name:=mergeCont ent(cI + 1)
cI = cI + 2
Case wordCommand.ins
WordObj.Selecti on.TypeText mergeContent(cI + 1)
cI = cI + 2
Case wordCommand.ins FootNote
With WordObj.ActiveD ocument.Bookmar ks
.Add Range:=WordObj. Selection.Range , Name:="fodn"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
WordObj.ActiveD ocument.Footnot es.Add
Range:=WordObj. Selection.Range , Reference:=""
WordObj.Selecti on.TypeText mergeContent(cI + 1)
WordObj.Selecti on.Goto What:=wdGoToBoo kmark, Name:="fodn"
WordObj.Selecti on.MoveRight Unit:=wdCharact er, Count:=1
cI = cI + 2
Case Else:
'nothing
End Select
Loop Until cI > cBound

WordObj.ActiveD ocument.SaveAs fileName:=destF ile, FileFormat:= _
wdFormatDocumen t, LockComments:=F alse, Password:="",
AddToRecentFile s:= _
True, WritePassword:= "", ReadOnlyRecomme nded:=False,
EmbedTrueTypeFo nts:= _
False, SaveNativePictu reFormat:=False , SaveFormsData:= False, _
SaveAsAOCELette r:=False
DoEvents
WordObj.Activat e

Set WordObj = Nothing

DoCmd.Hourglass False

Exit Function

TemplateError:
WordObj.Quit
Set WordObj = Nothing
Exit Function

End Function
</vba_code>

The array: Mergecontent is made by retrive table content using vba. This is
specific to my use and i won't explain the table content part. I use a
function showByAnsId(ans Id%) to make Mergecontent, and the way i use it (in
a form click buttom event) is:


<vba_code>

Private Sub CWord_Click()
Dim arr
On Error Resume Next
arr = showByAnsId(Ans !id)
If oneBeyondUBound (arr) Then
MergetoWord arr
End If
End Sub
</vba_code>


Just to illustate is here the funstion.

<vba_code>
Function showByAnsId(ans Id%)
Dim rs As Recordset, bmArr(), fa$, content$, headline$
Set rs = CurrentDb.OpenR ecordset( _
"SELECT " & _
"Firma.navn , Firma.adresse, Kontakt.kontakt person, Ans.headline, "
& _
"par.abr, Par.content, Ans.id, parliste.id AS parid " & _
"FROM " & _
"firma, Jobopslag, Ans, Parliste, Par, Kontakt " & _
"WHERE " & _
"Firma.ID=Jobop slag.firma and " & _
"Jobopslag.ID=A ns.jobOpslId and " & _
"Parliste.ansId =Ans.id and " & _
"Par.id=Parlist e.parId and " & _
"Kontakt.ansId= Ans.id and " & _
"Ans.id=" & ansId & _
" order by parliste.id" _
)
If Not rs.EOF Then
fa = rs![adresse]
headline = rs![headline]
add2BookMarkLis t bmArr, _
wordCommand.got oBMIns, "firma", rs![navn], _
wordCommand.got oBMIns, "att", rs![kontaktperson], _
wordCommand.got oBMIns, "FirmaAdrL1 ", Trim$(Split(fa,
",")(0)), _
wordCommand.got oBMIns, "FirmaAdrL2 ", Trim$(Split(fa,
",")(1)), _
wordCommand.got oBMIns, "headline", rs![headline], _
wordCommand.got oBMIns, "dato", Format(Date, "d") & ". " &
MonthName(Month (Date))
End If

Dim spaceDelim$
While Not rs.EOF
If (Right$(content , 1) = ">") Or (Left$(rs![content], 1) = "<") Or
_
Len(content) = 0 Then
spaceDelim = ""
Else
spaceDelim = " ": End If
content = content & spaceDelim & rs![content]
rs.MoveNext
Wend

Dim angelBBeg%, attVal%, tag As Collection

If Len(content) Then
add2BookMarkLis t bmArr, wordCommand.got oBM, "content"
Set tag = firstTag(conten t)
While tag.item(hasTag sKey)
angelBBeg = tag.item("<")
If angelBBeg > 1 Then
add2BookMarkLis t bmArr, wordCommand.ins , Left$(content,
angelBBeg - 1): End If
Select Case tag.item(tagKey )
Case "br", "br/", "/br"
add2BookMarkLis t bmArr, wordCommand.ins , vbCrLf
Case "indent"
attVal = valOrNull(tag, "length")
If Not IsNull(attVal) Then
add2BookMarkLis t bmArr, wordCommand.ind ent, attVal:
End If
Case "/indent"
add2BookMarkLis t bmArr, wordCommand.ind entBack
Case "mailId/"
add2BookMarkLis t bmArr, wordCommand.ins FootNote, _
"From:Be******* *****@it.dk, subj:'" & headline &
"',dato:" & Left$(Now, 16)
Case Else
'nothing
End Select
content = Right$(content, Len(content) - tag.item(">"))
Set tag = Nothing
Set tag = firstTag(conten t)
Wend
If Len(content) Then
add2BookMarkLis t bmArr, wordCommand.ins , content: End If: End
If
rs.Close
Set rs = Nothing
showByAnsId = bmArr
End Function
</vba_code>


Preceding vba code has some dependency. The following is what catches my
eyes, but just ask again if you are interested and i have missed something.


<vba_code>
Const tagKey$ = "tag"
Const hasTagsKey$ = "hasTags"

Sub add2BookMarkLis t(bmArr, ParamArray bMContentPairs( ))
Dim i%
For i = 0 To UBound(bMConten tPairs)
add2list bmArr, bMContentPairs( i)
Next
End Sub

Sub add2list(V, i)
On Error GoTo Err
ReDim Preserve V(UBound(V) + 1)
V(UBound(V)) = i
Exit Sub
Err:
ReDim V(0)
Resume Next
End Sub

Function oneBeyondUBound &(Var)
On Error Resume Next
oneBeyondUBound = 1 + UBound(Var)
End Function

Function firstTag(str$) As Collection
Dim tBegP%, tEndp%, inBracket$
Dim attPairs, tagContenSpcDel Item, maxCI%, tagCI%
Set firstTag = New Collection
tBegP = InStr(str, "<")
If tBegP Then
firstTag.Add -1, hasTagsKey
tEndp = InStr(tBegP, str, ">")
If tEndp > tBegP + 1 Then
inBracket = Replace(Trim(Mi d(str, tBegP + 1, tEndp - tBegP -
1)), " ", " ")
tagContenSpcDel Item = Split(inBracket , " ")
maxCI = UBound(tagConte nSpcDelItem)
If maxCI > -1 Then
firstTag.Add tagContenSpcDel Item(0), tagKey
If maxCI > 0 Then
For tagCI = 1 To maxCI
attPairs =
Split(Replace(R eplace(tagConte nSpcDelItem(tag CI), """", ""), "'", ""), "=")
If UBound(attPairs ) = 0 Then
firstTag.Add 0, attPairs(0)
Else
firstTag.Add attPairs(1), attPairs(0): End If:
Next: End If: End If: End If
firstTag.Add tBegP, "<"
If tEndp > tBegP Then
firstTag.Add tEndp, ">": End If
Else
firstTag.Add 0, hasTagsKey: End If
End Function
</vba_code>

And finaly, my references includes 'Microsoft word 8.0 object libary' and i
use access2000 and word97

--
Regards
Benny Andersen
Jan 12 '06 #2
<fo******@gmail .com> wrote:
I have a set of Access 2000 tables that I would like to export into a
MS Word 2000 template at specific bookmark locations that I've set up.

Would anyone know the code to achieve something like this? I've heard
about using the OutPutTo method, but I'm not sure if it can output to a
specific bookmark location.


The following will do what you want, I think, however, It is not nearly as
efficient nor as elegant as Albert Kallal's method here:

http://www.members.shaw.ca/AlbertKal.../msaccess.html
--------------------------
Dim mWord As Object
Dim cnxn As ADODB.Connectio n
Dim rL As ADODB.Recordset
Set cnxn = CurrentProject. Connection
Set rL = New ADODB.Recordset
Set mWord = CreateObject("W ord.Application ")
mWord.Documents .Add "C:\odis\odis_P PS_100_CaseClos ing.dot"
With mWord.ActiveDoc ument
.Bookmarks("off _name").Range.F ields(1).Result .Text =
GetOffenderName ()
rL.Open "current_su p", cnxn, adOpenForwardOn ly, adLockReadOnly,
adCmdTableDirec t
If Not rL.EOF Then
..Bookmarks("cs _open_date").Ra nge.Fields(1).R esult.Text =
rL.Fields("cs_o pen_date")
rL.Close
.Bookmarks("sup _adjustment").R ange.Fields(1). Result.Text =
Nz(Forms("Super visionForm")!me mAdjustment, "")
.Bookmarks("Tod ay").Range.Fiel ds(1).Result.Te xt = Date
End With
mWord.Visible = True
Set mWord = Nothing
-----------------------

--
Darryl Kerkeslager
Jan 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
23855
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how to use a database table but all I want to do now is to click a command button to display this access report. Any suggestions please ?????
15
13265
by: Mark C | last post by:
All, I have exhaustingly been looking through the newsgroups in search of a way to systemically output an Access 97 report to a pdf file using the full version of Adobe Acrobat. I want the user to be able to click a button and have the Access report saved as a pdf in a directory specified by me the programmer. I have seen a posting by...
1
2735
by: paul.hanti | last post by:
This board has been a plethora of information. Thanks to all that respond! I have a quick question regarding the built-in OutputTo macro. I've built a shared database in Access 2003 (in Access 2000 file format) that resides on a shared network drive. This OutputTo macro is essentially setup to export one small table to an Excel...
1
1886
by: joeygun | last post by:
I'm trying to do something I thought would be easy, and maybe it is, but I've spent the afternoon now reading about bookmarks, templates, Word mail merge, VBA, automation and am seemingly no farther along than I was when I started. All I want to do is link a dozen or so records (data type memo) from a query containing a single field into a...
6
2668
by: Ryan Muller | last post by:
My company just upgraded from Access 97 to Access 2003 today and we are having some issues in a database that generates a Word document from information selected in a form. Here is the code we were using without issue previous to the switch: 'Start Word and create a new doc from the template Set objWord = CreateObject("Word.Basic")...
42
11478
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
2
9484
by: Alan T | last post by:
How do I make use of the Bookmarks property so that I can write a text at/below the position of a particular bookmark or the first bookmark ? private Microsoft.Office.Interop.Word.Document myWordDoc = new Document(); myWordDoc.Bookmarks
4
5471
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing. i have done this one.Now what i need is to enable the users to upload files and save it into the corresponding table. Example: 3. A laser...
7
4633
by: TinyTom | last post by:
I really need help with this code. I have made a pretty complicated subform that automatically updates filter criteria based off of inputs in various fields within the search form. What I need to do is design a command button that will kick out the information that is stored in the subform to an excel document. Ideally I would like to use the...
0
7467
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7807
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.