Reply to topic  [ 10 posts ] 
Tables in MS Word help - macro/VB 
Author Message
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:46 pm
Posts: 10022
Reply with quote
Posted here for max exposure.

I'm trying to create a document in MS Word 2003 (what they use at work) with the idea being that if required, it can be loaded, filled and saved. Part of this means creating a form. What I'd like to do in the form is create either checkboxes or dropdown fields. The value of the field is recorded and basically a total score given.

For example, a depression questionnaire. The selectable answers would be: not at all, some days, most days, every day.

The questions would be:

1. I feel low...
2. I have little interest in doing things...
3. Poor appetite...

The idea is that 'not at all' = 0, 'some days' = 1, 'most days' = 2, 'every day' = 3. The scores are added up and a final score is given.

I've managed to create a table in Word, filled in the questions and created dropdown boxes for the answers with the options given above. What I need is for the next column to display a score based on the answers given and then give a total score at the bottom.

Any ideas on how to do this? It needs to be Word 2003 as it is launched from another program and the document is then saved within that program so the results can be seen at any time.

_________________
Image
He fights for the users.


Tue May 08, 2012 5:36 pm
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:46 pm
Posts: 10022
Reply with quote
Okay so a pic to show what I'm after:

Image

The first pic shows what the options are. In my head, each one has a score:
Not at all = 0
Several days = 1
More than half the days = 2
Nearly every day = 3

The far right cell should have the value based on what was selected in the middle cell. Total should then sum up the above cells and display a total!

I've looked into this and it goes beyond my programming skills. I've bugger all idea on how to achieve what I want and my google fu hasn't been helpful.

_________________
Image
He fights for the users.


Tue May 08, 2012 10:19 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
Should be able to do it with just conditional formatting to output a value, then sum the values, probably no programming involved

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Wed May 09, 2012 8:44 am
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
finlay666 wrote:
Should be able to do it with just conditional formatting to output a value, then sum the values, probably no programming involved

That's using Excel, non?

Is there any reason for the requirement for it to be an MS Word solution?

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Wed May 09, 2012 8:55 am
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:46 pm
Posts: 10022
Reply with quote
It's in word rather than excel so it doesn't seem to accept formulae or values (unless I'm doing something silly?).

I've done some research last night and so far this is what I've come up with:

Code:
Sub AddDropDownResults()



Dim Dropdown1, Dropdown2, Dropdown3, Dropdown4, Dropdown5, Dropdown6, Dropdown7, Dropdown8, Dropdown9 As Integer

Dropdown1 = Val(ActiveDocument.FormFields("DropDown1").Result)

Dropdown2 = Val(ActiveDocument.FormFields("DropDown2").Result)

Dropdown3 = Val(ActiveDocument.FormFields("DropDown3").Result)

Dropdown4 = Val(ActiveDocument.FormFields("DropDown4").Result)

Dropdown5 = Val(ActiveDocument.FormFields("DropDown5").Result)

Dropdown6 = Val(ActiveDocument.FormFields("DropDown6").Result)

Dropdown7 = Val(ActiveDocument.FormFields("DropDown7").Result)

Dropdown8 = Val(ActiveDocument.FormFields("DropDown8").Result)

Dropdown9 = Val(ActiveDocument.FormFields("DropDown9").Result)

ActiveDocument.FormFields("Text10").Result = Str(Dropdown1 + Dropdown2 + Dropdown3 + Dropdown4 + Dropdown5 + Dropdown6 + Dropdown7 + Dropdown8 + Dropdown9)

End Sub



What I need to do is now give values to each dropdown entry as stated in the previous post. Still looking into doing this. Once this is done, it may well work. I hope!

_________________
Image
He fights for the users.


Wed May 09, 2012 8:57 am
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:46 pm
Posts: 10022
Reply with quote
EddArmitage wrote:
Is there any reason for the requirement for it to be an MS Word solution?

Yes. The program I use is the one for medical records. It can tie in with MS Word so I've managed to create an asthma leaflet which when loaded, is filled in with the patient's name, recent lung tests and medications (which can then be used to explain which medications are for asthma, and what the best lung test result is). It won't tie in with excel and that's down to the original program and is not something I can change.

_________________
Image
He fights for the users.


Wed May 09, 2012 8:59 am
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
EddArmitage wrote:
finlay666 wrote:
Should be able to do it with just conditional formatting to output a value, then sum the values, probably no programming involved

That's using Excel, non?

Is there any reason for the requirement for it to be an MS Word solution?

I thought you could use the two, had to insert it as an Excel spreadsheet though, but was a long time since I did that though (if you can still do it)

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Wed May 09, 2012 11:45 am
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:46 pm
Posts: 10022
Reply with quote
I think you can embed a spreadsheet but that's different to a table in Word. A table is literally that - some lines. The "cells" are just boxes. No formulae/calculations.

I think it needs to be considered as a form in a Word document, rather than a (excel) table.

_________________
Image
He fights for the users.


Wed May 09, 2012 2:41 pm
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:25 pm
Posts: 10691
Location: Bramsche
Reply with quote
Tables in Word can have simple formulas in them.

_________________
"Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari

Executive Producer No Agenda Show 246


Thu May 10, 2012 4:33 am
Profile ICQ
What's a life?
User avatar

Joined: Thu Apr 23, 2009 8:46 pm
Posts: 10022
Reply with quote
*hits head*

Playing around and I found out the document has to be saved as an RTF so no macros. :(

Means I'll have to find other ways of doing this.

_________________
Image
He fights for the users.


Fri May 11, 2012 1:09 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.