Help!

Morten R

SeaSide
Local time
Today, 04:54
Joined
May 8, 2007
Messages
16
Hei, i working with this merge thing. The code i'm using put in bookmarks in a Word doc. I have run in a problem when the bookmark is selected in diffrent order than bookmark1, bookmark2. In some doc i start with bookmark4, and bookmark5 in the top of the doc. It then only take the mark wit low noumbers, and forget the rest. Can somone plz tel med howe to cange this code so it maby due a loop or somthing??
Code:
Private Sub cmdSend_Click()
Beep
Select Case MsgBox("Skal vi lage et Word dokument?" & vbCrLf, vbYesNo + vbQuestion, "Starter word")
Case vbYes:
Dim WordApp As Word.Application
Dim strTemplateLocation As String
strTemplateLocation = Tekst135

On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
On Error GoTo ErrHandler

WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False

With WordApp.Selection

.GoTo what:=wdGoToBookmark, Name:="bookmark1"
.TypeText [Fornavn klager]

.GoTo what:=wdGoToBookmark, Name:="bookmark2"
.TypeText [Etternavn Klager]

.GoTo what:=wdGoToBookmark, Name:="bookmark3"
.TypeText [Adresse]

.GoTo what:=wdGoToBookmark, Name:="bookmark4"
.TypeText [Hovedtabell.Postnr]

.GoTo what:=wdGoToBookmark, Name:="bookmark5"
.TypeText [Sted]

If IsNull(rmalogged) Then
.TypeText "WHATEVER"

End If

.GoTo what:=wdGoToBookmark, Name:="bookmarktop"
.TypeText " "

End With
DoEvents
WordApp.Activate
Set WordApp = Nothing

ErrHandler:
Set WordApp = Nothing

Case vbNo: 'Do not save or undo
'Do nothing

'Case vbCancel: 'Undo the changes
'DoCmd.RunCommand acCmdUndo
'Me.tbProperSave.Value = "No"

Case Else: 'Default case to trap any errors
'Do nothing

End Select
End Sub
 

Users who are viewing this thread

Back
Top Bottom