Importing Data from MS Word Form (1 Viewer)

XelaIrodavlas

Registered User.
Local time
Today, 01:10
Joined
Oct 26, 2012
Messages
174
Hi All,

I am trying to create a form for users in MS Word (although any commonly accessible software would be fine) with the plan to import the data into my Access database. However I am not sure how to setup the Word Document or identify the correct controls from which to extract the data.

Word is clearly setup differently to Access and I have never used its 'advanced' options. Does anyone know of/have any helpful examples they could lend me to get started? I am confident if I can get the Word form setup correctly I can work the rest out for myself.

To give an example of my problem. In the below Thread I saw some helpful code which the OP says works fine, but how is he referring to the Data in Word???
(https://www.access-programmers.co.uk/forums/showthread.php?t=257482&highlight=import+word+form+data)

Many thanks :)


Edit:
Further to my frustrations... I opened Developer Tab in Word and added a simple combo box with Yes/No for options, I named it 'combotest' by clicking on its properties, then run the following test code in the VB immediate window:
msgbox ActiveDocument.FormFields("combotest").Result
But i get an error 'the requested member of the collection does not exist..'
Leading me to believe I have not named the combo box correctly? So how should I name it? :/
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 01:10
Joined
Jan 14, 2017
Messages
18,221
I haven't done this for years but a few things to consider:

1. Use a Word form checkbox for yes/no values rather than a combo box

2. first you need to define the Word application in Access then refer to it:
Code:
'Open the file in Microsoft Word
        Dim stDocName As String
        stDocName = "MyWordFilePath"  <== 'alter as necessary
        Set oApp = CreateObject("Word.Application")
        'Make the application visible.
        oApp.visible = True
        'Open the document.
        oApp.Documents.Open stDocName

        .....
      'return values from word doc in your Access form like this
       Me.AccessCheckbox = oApp.ActiveDocument.FormFields("MyWordCheckBox").CheckBox.Value

       Me.AccessTextbox = oApp.ActiveDocument.FormFields("MyWordTextBox").Result

HTH
 

XelaIrodavlas

Registered User.
Local time
Today, 01:10
Joined
Oct 26, 2012
Messages
174
Thanks Ridders this is just the sort of help I need.

I've added a checkbox and tested the code, it's getting stuck at this line:
oApp.ActiveDocument.FormFields("MyWordCheckBox").CheckBox.Value

Returning the same error (5941, The Requested Member of the collection does not exist)

Do you know the proper way I should be naming the Checkbox? (I am currently changing it's title in the content control properties)

Thanks again,
 

isladogs

MVP / VIP
Local time
Today, 01:10
Joined
Jan 14, 2017
Messages
18,221
You need to change the values to whatever your controls are called.
Do this for both Word and Access controls

So if its you have a checkbox in Word called chkTest & a Word textbox called txtHello then that part of the code should be:

Code:
=oApp.ActiveDocument.FormFields("chkTest").CheckBox.Value

Code:
=oApp.ActiveDocument.FormFields("txtHello").Result
 

XelaIrodavlas

Registered User.
Local time
Today, 01:10
Joined
Oct 26, 2012
Messages
174
You need to change the values to whatever your controls are called.

Ah ok... then this will be a really dumb question... how do I know what the controls are called?

Thanks again for your help :D
 

isladogs

MVP / VIP
Local time
Today, 01:10
Joined
Jan 14, 2017
Messages
18,221
Yes I agree with you .... :)

Change the Access form to Design view.
Make sure the property sheet is open
Click on a control and read its name ....

For example:

 

Attachments

  • Capture.PNG
    Capture.PNG
    11 KB · Views: 246

XelaIrodavlas

Registered User.
Local time
Today, 01:10
Joined
Oct 26, 2012
Messages
174
Sorry, I meant how do you check the name of the control in Word?
 

isladogs

MVP / VIP
Local time
Today, 01:10
Joined
Jan 14, 2017
Messages
18,221
I thought it was too easy....!
As i hadn't done this for over 10 years, I had to check first...

Use bookmarks to refer to the Word form controls
In Word, go to the Insert ... Bookmarks ribbon item
Add a bookmark then link the bookmark to a form control

If you already have lots of bookmarks you may not remember what each one refers to.
If so, select each one in turn & click Go To

The selected control will be highlighted - actually shaded grey



The form shown above has over 150 controls - I remember it took many hours to link all controls to Access

if you need more help, hopefully someone else who does this regularly will be able to assist

Good luck & have fun :D
 

Attachments

  • Capture.PNG
    Capture.PNG
    37.7 KB · Views: 220

XelaIrodavlas

Registered User.
Local time
Today, 01:10
Joined
Oct 26, 2012
Messages
174
Awesome thanks a bunch, I would have never figured that out alone.

This should be enough to get me going now, wish me luck! :)
 

XelaIrodavlas

Registered User.
Local time
Today, 01:10
Joined
Oct 26, 2012
Messages
174
In case anyone else is struggling and happens upon this thread, here's what solved my problem...

All the advice and code I've found online (including that helpfully provided by the above) online only applies to Word's LEGACY controls. It would seem that at some point in the last however-many updates, Microsoft introduced newer controls, that while pretty, lack the old ability to interact with VBA (as far as I can tell!)

So if you're like me and using a newer version of word, make sure you use Legacy controls (found in the Developer Ribbon at the bottom of the new controls) rather than the new whatever-they-call-ems, or activeX controls. Then you can refer to the controls easily, as per the advice given above.

And FYI, you can still format Legacy controls to your specifications, and restrict permissions on the form to 'filling in forms' only, so the user doesn't delete them by mistake.

Hopefully this will prove useful to someone down the line, and you wont be like me doing this ( :banghead: ) for as long as I did...

Thanks Again!
 

Users who are viewing this thread

Top Bottom