tommeke1980
Gebruiker
- Lid geworden
- 21 sep 2003
- Berichten
- 11
Wanneer ik een nieuw document aanmaak op basis van mijn word-template verloopt alles zoals gewenst. Wanneer ik dit echter vanuit Access wil aanmaken, loopt de code vast.
Iemand een idee?
Tom
Dit is de code van de Word-template (de datum wordt nog wel aangemaakt - bij de header loopt het mis):
Dit is de code die de template oproept:
Iemand een idee?
Tom
Dit is de code van de Word-template (de datum wordt nog wel aangemaakt - bij de header loopt het mis):
Code:
Private Sub Document_New()
Dim sDate As String
Dim strVoornaam As String
Dim strFamilieNaam As String
Dim strSchool As String
Dim strKlas As String
Dim strInstellingenPath As String
' De datum wordt automatisch aangemaakt
sDate = Format$(Date + 1, "Dddd dd mmmm yyyy")
ActiveDocument.Bookmarks.Item("bmDatum").Range.Text = sDate
' Via volgende code wordt de header ingevuld
strInstellingenPath = ThisDocument.Path & "\instellingen.txt"
If Dir(strInstellingenPath) > "" Then
Open strInstellingenPath For Input As #1
Input #1, strVoornaam, strFamilieNaam, strSchool, strKlas
Close
If strVoornaam = "" Or strFamilieNaam = "" Or strSchool = "" Or strKlas = "" Then
Exit Sub
Else
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="Schoolagenda " & strSchool & " " & "Klas " & strKlas & " - " & strVoornaam & " " & strFamilieNaam
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(-0.63)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End If
End If
' De cursor komt in de eerste cel te staan
ActiveDocument.Tables(1).Cell(3, 2).Select
End Sub
Dit is de code die de template oproept:
Code:
Sub CreateWLetter()
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim strPath As String
On Error GoTo ErrorHandler
strPath = databasepad & "\agenda.dot"
Set oWord = GetObject(, "Word.Application")
With oWord
Set oDoc = oWord.Documents.Add(strPath)
With oDoc
'Hier kun je code instellen voor handelingen binnen het document
End With
.WindowState = wdWindowStateMaximize
.Visible = True
.Activate
End With
ErrorHandlerExit:
Set oDoc = Nothing
Set oWord = Nothing
Exit Sub
ErrorHandler:
If Err.Number = 429 Then
Set oWord = CreateObject("Word.Application")
Err = 0
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub