Results 1 to 4 of 4
  1. #1
    silverspr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    19

    Call word object and import word fields

    I'm opening a word document from within MsAccess, then writing the field count and field results to a text file for import into a survey table. The field count is later mapped to the question id in the master survey table. The text file and header for the text file are created in the preceding procedure.



    This code won't work (at least I can't get it to) unless I remark out "Dim afield as word.field". This boggles my mind, afield is referenced throughout the procedure, how can it possibly work and how do I fix this?! Thanks in advance. Sorry if I didn't do the [Code] tags right...Also attached the output of the text file (temp1).

    [Code]
    Sub GetFld()
    Dim count As Integer
    'Dim afield As Word.Field
    On Error Resume Next


    Open "G:\Desktop\Temp1.txt" For Append As #1


    count = 0




    For Each afield In ActiveDocument.FormFields
    'If afield.Type = wdFieldFormTextInput Then
    count = count + 1
    'Debug.Print count & "," & afield.Result
    'Else: count = count
    Print #1, """" & count & """" & Chr(59) & """" & afield.Result & """" & Chr(59) & """" & ActiveDocument.FormFields("Text3").Result & """"

    Next afield
    Close #1
    'MsgBox "output complete"
    End Sub
    [Code]
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Ending code tag needs /: [/code]


    I am confused. That code doesn't show opening Word document, it shows opening a txt document that is delimited with semi-colons. How are you 'opening a word document from within Access'?

    I use Option Explicit in all modules which means all variables must be declared. I uncomment the Dim line and run code. It doesn't error because of the On Error Resume Next but also doesn't do anything because ActiveDocument is an object variable that has not been set. Why do you have the On Error code? This interferes with debugging.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    silverspr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    19
    Opps, well that explains the no error...I feel foolish, I've looked at that code for 2 days and didn't even clue in!! I've added the declaration Option Explicit, remarked out the On Error...
    Ok not sure what to set the activedocument object to. The word form is opened in the another procedure, which calls this procedure "Sub GetFld". The temp text file I attached is the output of the form called by this subroutine.

    thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If the Word file is opened as an object in one procedure then the other procedure has no awareness of that object. I have never tried to declare/set/open a file (Word, Excel) object globally so that it is available to multiple procedures but I suppose it is possible.

    However, you were getting the desired output? I don't know how that could be.

    Can you just combine the two procedures?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Access to Word - Multiple Word Templates?
    By alpinegroove in forum Programming
    Replies: 11
    Last Post: 06-12-2012, 04:42 PM
  2. scaling Word OLE object in Access Report
    By Jeff Perkins in forum Reports
    Replies: 1
    Last Post: 09-11-2011, 03:18 PM
  3. Import Word document using VBA
    By degras in forum Import/Export Data
    Replies: 4
    Last Post: 04-12-2011, 02:40 AM
  4. Replies: 0
    Last Post: 11-23-2010, 05:34 AM
  5. Replies: 0
    Last Post: 06-14-2010, 07:19 AM

Tags for this Thread

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