How to use option buttons to change a value in a Word 2016 table - vba

I am attempting to create a form that uses option buttons to assign a score, which would later be totaled for evaluation purposes. (I am using Word 2016 on Windows 10.)
Here is a pic of a portion of the proposed form, with 5 columns:Proposed Form
Here is a picture of the code I have attempted to use, which worked just exactly as I wanted it to "in EXCEL." Due to needs in other parts of the form, however we will be using Word, not Excel.Code Pic
Since we've decided to use Word, due to other features that Excel lacks, what code should I be using that would place a point value in the "Points" column? (I am assuming e2 to be the address of the 2nd row, 5th column?). I have spent 2 days so far trying to understand how to make this work. I know it can be done, but I lack the specific coding knowledge to make it happen. Thanks in advance for your help!

You appear to be using both formfields and ActiveX controls. It would be far simpler to use just formfields and, instead of having radio buttons, a simple dropdown for each item. That way, you don't need all those separate columns and the results could be tallied from the dropdown selections without the need for VBA.

Related

Can Access ensure a new form record displays all fields?

I have a database where I don't want some fields showing depending on data in other fields. I'm still new to VBA, having learnt how to do things I need via the internet (there's not much call for it in my job so like to try it out on side projects) for the things I need and have managed to create some code that hides certain fields that aren't needed, depending on what's been entered in another field and that works okay, if not perfectly (I'd like it to only work on the current record and not all of them at once but will worry about that later). My problem is, if I'm entering information onto a record and any of those fields become invisible exactly as I would want them to, then if I have more records to complete and load a new record, those hidden fields are also hidden on the blank record before any data has been entered and I want each new record to show all fields from the outset.
Another thing I've noticed is that if I close the database, next time I go into it the hidden fields have unhidden themselves again so I know I'm missing something important.
Here's a screenshot of a bit of the code where I want 2 other fields (What_reason and Date_sent_to_new_owning_School) to be visible depending on whether the answer in the current field after update is "Standard" or "Non-standard":
I'm sorry if this is really entry-level stuff but I AM entry level and trying to learn. This bit does work, albeit not perfectly as I'd like it to only work on the record I'm in at the time, and not go through and hide that field in all the other records at once (which it's doing).
I've searched everywhere but can't find the answer and although I've tried, I'm nowhere near good enough at VBA to try and use common sense to work it out. Is this something that can be done? I'm okay with computers generally and with Access too but I'm aware there's an awful lot I don't know and this is why I'm trying to do new things and learn stuff that I've not used before. I have tried all day to get this to work but am admitting defeat and am hoping somebody here will be able to help me. I'll probably need 'idiot level' advice if that's possible, I know my limitations. :)
Do you know how to use the Event tab in the Property Sheet? You can set all of your fields to [field].Visible = True on either: On Current, On Load, or On Open
Screenshot of the Property Sheet and for the field that determines the visibility of all of the other fields; you can use the Event: After Update so that way when you click/tab away from that field, it'll make those changes for you!
Property setting affects ALL instances of control. Control will be visible/not visible for all records depending on conditions of current record. Therefore, dynamically hiding controls on form set in Continuous or Datasheet will NOT give the desired result of
only work on the current record and not all of them at once
Db is not going to 'remember' dynamic setting - code needs to be executed when form opens and/or navigating records - so it is needed in OnCurrent event as well as control's AfterUpdate.
Conditional Formatting can dynamically enable/disable textbox/combobox by record although control is still visible.

Forms not saving

Firstly, I apologise for my terminology and sometimes stupidity, as I am completely self/internet (mostly on here) taught. I've been developing an app for the past few years, mostly to help me with work, and more for kicks and giggles. I have now run into a problem that has me stumped! So I am calling out for any suggestions please :)
Okay, some background, I use colours on all forms to identify blocks of data based on an ID - it looks pretty, okay; and sometimes it's a quick identifier of which block the data belongs to when skimming through tables. So I have a form where I or the user can change these colours to whatever suits their eyes, needs etc. and there is a table that holds this information. Now these colours are applied using the 'Conditional Formatting' (when ID = 1 then background this colour, font that colour, etc). When a Form is opened in the FormLoad() code there is a check to see if the colours have been changed and if so then a module is called which updates all the 'Conditional Formats' on the Form (I should add here that it's only applied to the tables on the form), and everything looks pretty and more important works! Now this process is relatively slow (a couple of seconds on some forms), too slow to run every time the form is opened. So ages ago I found a way to force Access to save the design, including the 'Conditional Formatting':
DoCmd.RunCommand (acCmdDesignView)
Forms!PrePlanner!BtnHelp.Caption = "Help"
DoCmd.Save acForm, "PrePlanner"
DoCmd.Close acForm, "PrePlanner", acSaveYes
This works perfectly on some forms but not on other!!
At first I thought it was something to do with the subForms, as it WASN'T working on all the forms that have subForms and the ones it was working on had no subForms... So I copied one of a simple subForms (a recently created form) which can open as a normal form, made changes to the colours opened the TEST form, the colours updated as expected, closed the form with the above code and the Formatting WASN'T saved! :( (If I change the Help Button to say "Help!" this change IS saved)
The Forms that don't save with the above code are also the most recent Forms that I have designed, the ones that do save are older forms (a couple years old and designed on a different computer but the same version of Access). I copied one of these older Forms, changed the colours, etc etc and this it DID save!!!
I've been through and compared all the properties of a working form and a nonworking form and nothing, I've tried exporting and importing... Please any thoughts would really help my sanity!!
Thanks in advance
....I forgot to say that I'm using Access 2016 on a 64bit Windows 10 machine.
Additional Info.
Having played around this morning, I created a new form (from scratch) configured the records so that the Conditional Formatting can be applied, etc. Opened the new form the Conditional Formatting was updated, the form closed and saved. Upon reopening the new form everything was as it should be the Conditional Formatting was saved. So I then add a subForm, and tried again, the Conditional Formatting was updated, the from closed BUT this time without saving the Conditional Formatting!! I then removed the subForm and repeated the test, this time the Conditional Formatting was saved.
So it seems to be something to do with subForms, what changes to the form properties does adding a subForm trigger that would stop the Conditional Formatting from being saved? Is this a quirk in Access?
Thanks again.
Have you tried running your code to apply the formatting while the form is in design view? It seems like conditional formatting and properties don't save when updated via VBA while the form is in normal view mode. I've had good luck reopening the form in design, running the code, and then saving the form.

Checkboxes to generate letter

I am currently building a User form for some letters we use at work and I would like to design the userform to generate the letter with mostly just checkboxes. e.g.
Your application cannot be completed until the following is received:
A Statutory declaration providing a statement in regards to your: financial situation
In the above example I would need two checkboxes.
Checkbox 1:
A statutory declaration providing a statement in regards to your:
Checkbox2:
financial situation
I guess the question I am asking is in two parts:
1: How do I get checkboxes to generate text?
2: How do I get multiple checkboxes to generate text against the same bookmark/s?
I may not need a Statutory Declaration, I may need a "certified copy of:" ---"bank details, proof of identity, proof of citizenship"
As you can tell from the user form it's pretty extensive and all the checkboxes in the lower half of the form need to generate text.
Grateful for any advice or direction or resources or anything.
In theory, you might store the text to be inserted in your letter in the Check box's caption property and use code to insert the text into your letter when the box is checked. I think this is cumbersome and recommend that you use the caption for a caption, for example, "Statutory declaration". If it is checked such a paragraph is inserted into the letter, else it is left out.
The required declaration may include one or several of many items. Since you are thinking of check boxes, you could have one for each "bank details", "proof of identity", "proof of citizenship". These selections are very short and could be placed in the caption property. But if the texts are longer or of greatly varying lengths I would recommend the use of text boxes instead. So, if Cbx1 is clicked, the text of Tbx1 is inserted etc.
Alternatively, if only one item is required you might consider a dropdown. Or you might use a list box with multiple choices. In principle, I think that using different systems for different levels of decision making helps the user to find his way through your form. For example, use check boxes to select paragraphs (the full text of which might be shown in adjacent text boxes), and then switch to list boxes, option buttons, dropdowns or check boxes which look completely different to specify the contents of the selected paragraph. All of that detail might as well be hidden until the user has checked its box.

VBA script to insert anchor position for autoshapes in Microsoft Word 2007

I'm beyond the limits of my kindergarten-level VBA skills so would like to ask if anyone here can help me write a VBA script to help me work stepwise through my Word document and adjust the anchoring position of all the AutoShapes in the document.
I have a 400-page book in Microsoft Word with at least one and sometimes several marginalia (sidenote) on each page in a thin column to the left of the main body text column. These sidenotes are a concise 'pointer' to a particular point made in the body text and need to appear directly to that point's left.
Each sidenote is in its own AutoShape (within a textbox in that shape). The AutoShapes were placed by the author in an inconsistent way. Mostly they are anchored to a position on the page.
However, I need to repaginate. This will cause the body text to flow differently and I need the sidenotes to flow with it (approximately or exactly)!
So before I repaginate I want to make sure I anchor each AutoShape to the paragraph it belongs to and not to the page it is currently on.
I don't know if that can be done automatically, since I don't know how Word could deduce a purely spatial relationship between an AutoShape and a paragraph.
So I'm guessing I have to make do with a "semi-automatic" process. Something like this:
Press a button to start VBA script
Select next AutoShape
Prompt for user to enter cursor in body text where anchor is to be placed
Resume macro
Place anchor for that AutoShape in that position
Change vertical position paramater of AutoShape to "relative to paragraph"
and "0 mm"
(Alternative, not 0 mm but another value deduced to more
accurately position AutoShape)
Change width parameter of AutoShape to
a particular fixed value 37 mm (some of them were a little
inaccurately drawn)
End cycle and go back to beginning to
Select next AutoShape
Hope that is all understandable.
I've tried to record a VBA script to do some of this but have no idea how to build in the user prompt.
Any help much appreciated!
Craig
You may be better off creating a macro that works on one shape at a time, or anchor all the shapes manually (which you're almost doing anyway) and then write a macro to take care of the various parameters and settings you want.
If you really want to prompt the user while the macro is running you'll need to look into modeless dialogs (not possible on the Mac). See this link: http://www.bettersolutions.com/vba/VXV113/SE846743531.htm
Basically, you'd have to create your own dialog and then show it modelessly so that the user could still place the cursor before hitting OK. If you're new to VBA, this could be difficult to set up.
While searching for solutions to this, I found a post on another forum from someone trying to do something very similar. He was developing a set of tools for editors using Word and until I find the ultimate solution I am using his "Shapes" tool which allows me to change parameters on each AutoShape I select at-a-click instead of opening up and closing a dialogue box each time, plus selecting a different tab each time... His tools can be downloaded at his Editors' Toolkit website.

How to Make Exception Handling on VBA Excel Form Combobox?

I have this userform that i'm developing for my report formatting task. My whole code is finished, there are only 2 problems that i need to work on.
Making my VBA application work on every excel file that user choose
Exception Handling for ComboBoxes on my form.
(Edit: I hope trying to get attention of people who are interested in this question to another stackoverflow.com topic is not against forum rules)
You guys can reach first problem's topic from here: (There is already one suggestion but i'm little bit confused. So it would be super for alternative suggestions) http://bit.ly/VnF3cK
And about my second problem, when i click empty place of combobox, i can type whatever i want, but i want to restrict it, so users can only choose values [1-5] that i put inside of combobox. How can I achieve this?
In answer to your secondary question, you need to change the ComboBox's Style property to frmStyleDropDownList