Hello,
I'm currently trying to fill Text Form Fields in Word from Access data.
This works as long as I use the data of the form where the command button is located. In other words as long as I refer to the data with "Me!..."
However, I also need to include data from other forms. I thought this would be very simple but the values aren't copied. In the example below, the last line that starts with ".FormFields" - .FormFields("Uparam_pH").Result = Form!Dataanalyse_urineparam!pH - doesn't seem to work.
Anyone have an idea on what I might need to add to my code to make it work?
Thanks in advance
Private Sub Command457_Click()
'Print to word'.
Set appWord = CreateObject("Word.Application")
'Avoid error 429, when Word isn't open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Open("H:\DRAFT BL - UR - VITR.docx", , True)
With doc
.FormFields("Geg_Verslagnr").Result = Me!Dossier_Nummer
.FormFields("Geg_Notitienr").Result = Me!Notitie_Nummer
.FormFields("Geg_TitelMag").Result = Me!Magistraten_Aanspreektitel
.FormFields("Geg_NaamMag").Result = Me!Onderzoeksrechter_aanstelling
.FormFields("Geg_FunctieMag").Result = Me!Functie
.FormFields("Geg_Rechtsgebied").Result = Me!Magistraten_Rechtsgebied
.FormFields("Geg_AdresMag").Result = Me!Magistraten_Adres
.FormFields("Geg_TijdAfname").Result = Me!Tijdstip_afname
.FormFields("Geg_NaamSlachtoffer").Result = Me!Naam
.FormFields("Geg_Opdracht").Result = Me!Opdracht
.FormFields("Geg_Prelev").Result = Me!Prevelementen
.FormFields("Geg_TitelGenees").Result = Me!Wetsgeneesheren_Aanspreektitel
.FormFields("Geg_NaamGenees").Result = Me!Wetsgeneesheer
.FormFields("Geg_InstituutGenees").Result = Me!Institituut
.FormFields("Geg_DatumOntv").Result = Me!Datum_Ontvangst
.FormFields("Geg_Koerier").Result = Me!Koerier
.FormFields("Geg_Levering").Result = Me!Opgehaald_geleverd
.FormFields("Geg_Startanalyse").Result = Me!Startdatum_analyse
.FormFields("Geg_Eindanalyse").Result = Me!Einddatum_analyse
.FormFields("Uparam_pH").Result = Form!Dataanalyse_urineparam!pH
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub