I've made an Access 2007 database to store information about the lessonplans I have to make every schoolyear.
I want to export the data form the table "Lesvoorbereiding" (
Lessonplans in English) to Word using a readymade template (NLD-LV1.dotx). All works well except for the multivalued fields 'Lesuur' (
Lessonhour) and 'Werkvormen' (
Used activities) and the field 'Lesverloop' (
Lessonflow?), i.e. a field where you can link to documents, etc. on the harddisk of you pc. I don't know the English term for the property of this field, but in Dutch it has the property 'bijlage' (
attachment).
This is the code I use to activate the procedure when clicking the "KnopLesAfdrukken"-button in the form Lesvoorbereiding (
Lessonplans):
- Private Sub KnopLesAfdrukken_Click() 'ButtonPrintLesson
-
'Export a chosen lessonplan to Word
-
On Error Resume Next
-
Dim rstLesvoorbereiding As New ADODB.Recordset
-
Dim sSQL As String
-
Dim WordObj As New Word.Application
-
sSQL = "SELECT * FROM Lesvoorbereiding " & "WHERE LesId = " & Forms!FormLesvoorbereiding![LesId]
-
rstLesvoorbereiding.Open sSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
-
If rstLesvoorbereiding.EOF Then
-
MsgBox "Kan de les niet afdrukken.", vbOKOnly 'Can't print the lesson.
-
Exit Sub
-
End If
-
-
DoCmd.Hourglass True
-
-
Set WordObj = GetObject(, "Word.Application")
-
If Err.Number <> 0 Then
-
Set WordObj = CreateObject("Word.Application")
-
End If
-
-
WordObj.Documents.Add Template:="C:\Documents and Settings\Ida\Application Data\Microsoft\Sjablonen\NLD-LV1.dotx", NewTemplate:=False
-
-
With WordObj.Selection
-
.GoTo what:=wdGoToBookmark, Name:="Klas" 'Class
-
.TypeText rstLesvoorbereiding![Klas]
-
-
.GoTo what:=wdGoToBookmark, Name:="Datum" 'Date
-
.TypeText rstLesvoorbereiding![Datum]
-
-
Do Until rstLesvoorbereiding.EOF
-
.GoTo what:=wdGoToBookmark, Name:="Lesuur" 'Lessonhour
-
.TypeText rstLesvoorbereiding![Lesuur_Value] & ", "
-
rstLesvoorbereiding.MoveNext
-
Loop
-
-
.GoTo what:=wdGoToBookmark, Name:="LesId" 'LessonId
-
.TypeText rstLesvoorbereiding![LesId]
-
-
.GoTo what:=wdGoToBookmark, Name:="Onderwerp" 'Subject
-
.TypeText rstLesvoorbereiding![Onderwerp]
-
-
.GoTo what:=wdGoToBookmark, Name:="Materiaal" 'Used materials
-
.TypeText rstLesvoorbereiding![Materiaal]
-
-
Do Until rstLesvoorbereiding.EOF
.GoTo what:=wdGoToBookmark, Name:="Lesverloop" 'Lessonflow, pupils worksheets, etc.
If IsNull(rstLesvoorbereiding![FileName]) Then -
.TypeText " "
-
Else
-
.TypeText rstLesvoorbereiding![FileName]
-
End If
Loop
Do Until rstLesvoorbereiding.EOF -
.GoTo what:=wdGoToBookmark, Name:="Werkvormen" 'Activities
-
.TypeText rstLesvoorbereiding![Werkvormen_Value]
Loop
.GoTo what:=wdGoToBookmark, Name:="Opmerkingen" 'Remarks -
If IsNull(rstLesvoorbereiding![Opmerkingen]) Then
-
.TypeText " "
-
Else
-
.TypeText rstLesvoorbereiding![Opmerkingen]
-
End If
-
-
DoEvents
-
WordObj.Activate
-
WordObj.Visible = True
-
End With
-
-
Set WordObj = Nothing
-
DoCmd.Hourglass False
-
-
End Sub
Using this code I can export the value of all records in the table, except for the value of the fields mentioned above.
I've read about every page in the Access helpfile (Dutch and English version), but can't find an answer.
My knowlegde of VBA is very basic and limited. Can anybody tell me what is wrong or missing?