Home > Mobile >  How to line break between records within the same bookmark?
How to line break between records within the same bookmark?

Time:06-05

I'm currently trying to merge the data from msaccess to a word template that has bookmarks in place.

I currently have the code below,

Dim wApp as Word.Application
Dim wDoc as Word.Document
Dim rs As Dao.Recordset
    
set wApp=Word.document
set wdoc = wapp.documents.open(filepath)
set rs = currentdb.openrecordset("ftions")
    
rs.movelast
rs.movefirst
do while not rs.eof
    doevents 
        wdoc.bookmarks("Fname").Range.Text = Nz(rs!Fname, "")

rs.MoveNext
Loop

Set doc = nothing
Set wdoc = nothing
rs.close
set rs = nothing

end sub

However, my output becomes like this instead

[fname1][fname2]

when I want them to appear in a list

a. [fname1]

b. [fname2]

CodePudding user response:

As suggested by braX, issue was solved with

Dim wApp as Word.Application
Dim wDoc as Word.Document
Dim rs As Dao.Recordset
    
set wApp=Word.document
set wdoc = wapp.documents.open(filepath)
set rs = currentdb.openrecordset("ftions")
    
rs.movelast
rs.movefirst
do while not rs.eof
    doevents 
        wdoc.bookmarks("Fname").Range.Text = "• " & Nz(rs!Fname, "") & vbCrLf

rs.MoveNext
Loop

Set doc = nothing
Set wdoc = nothing
rs.close
set rs = nothing

end sub

CodePudding user response:

As per my comments above, just use this in your loop. (bullets included)

wdoc.bookmarks("Fname").Range.Text = "• " & Nz(rs!Fname, "") & vbCrLf
  • Related