Results 1 to 6 of 6
  1. #1
    kegoosse is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2017
    Posts
    6

    Fill in Word Text Form Fields from multiple Access forms

    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

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    First question, in this kind of problem, would be is the Dataanalyse_urineparam form Open and Visible when this occurs, as it has to be?

    But I suspect that your problem is here:

    Form!Dataanalyse_urineparam!pH

    Can't check it right now, but I believe the correct syntax is

    Forms!Dataanalyse_urineparam!pH

    Linq ;0)>

  3. #3
    kegoosse is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2017
    Posts
    6
    Yep, sorry for that missing -s- (schoolboy error). It is however not the only issue...

    I indeed figured that the form would have to be open and I tried including the following code, but still it doesn't work

    ...
    .FormFields("Geg_Eindanalyse").Result = Me!Einddatum_analyse
    DoCmd.OpenForm "Dataanalyse_urineparam", acNormal, "", "", , acNormal
    .FormFields("Uparam_pH").Result = Forms!Dataanalyse_urineparam!pH
    DoCmd.Close acForm, "Dataanalyse_urineparam"
    .Visible = True
    ...

    Is there some other code I need to use to open the form and make it visible?

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The item in red is not valid for this parameter

    DoCmd.OpenForm "Dataanalyse_urineparam", acNormal, "", "", , acNormal

    It should be

    DoCmd.OpenForm "Dataanalyse_urineparam", acNormal, "", "", , acWindowNormal

    Also, if the no item is needed, for a gieven parameter, as above, you can simply leave it blank...no need for te Zero-Length Strings ("")

    Linq ;0)>

  5. #5
    kegoosse is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2017
    Posts
    6
    I tried the suggested adjustment, but it still doesn't work.

    I'm sure it has to do with the inability of my current code to get the data from a different form, because when I move the information to the form where the command button is everything goes right.

    Like this:
    .FormFields("Uparam_pH").Result = Me!pH

    Moving everything to a single form, however, isn't an option because I have > 300 different items that need to be copied to Word, and a single form is limited to 255 different items.

    Any other suggestions on what adaptations can be made to get that data from that form?


    Thanks for the help so far Linq

  6. #6
    kegoosse is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2017
    Posts
    6
    I got it to work

    I use this code

    .FormFields("Uparam_pH").Result = Forms("Dataanalyse_urineparam").pH

    Does anyone know why this works and the version with the exclamation marks doesn't?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-10-2012, 09:47 PM
  2. Auto-Fill text fields in the form
    By sk88 in forum Access
    Replies: 2
    Last Post: 01-10-2012, 08:22 PM
  3. Access to Word Form Fill
    By defy in forum Programming
    Replies: 1
    Last Post: 10-04-2011, 12:10 AM
  4. Auto fill-in text box on forms
    By windwardmi in forum Forms
    Replies: 7
    Last Post: 09-13-2010, 02:47 PM
  5. How To Fill In Multiple Fields From A Form
    By SamanthaSamuels in forum Access
    Replies: 3
    Last Post: 08-16-2010, 12:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums