#1
|
|||
|
|||
Form Field - Drop down selection causing auto text
I do inspection work on submarines that must be documented. Each Boat has it own ID code that I would like to appear in another are of the form based on what boat I select from a Form filed drop down list. Please see the attachment: Block one I select a boat in the drop down. In block 2 I would like the first 5 numbers to automatically appear based on the selection in block 1. Currently they are in matching order but it is easy to mis-select the wrong 5 digit number if you are not careful or familiar with the layout. I have no preference for how its done, just that it works...(VBA or Macro) |
#2
|
|||
|
|||
The first sentences should read:
I hope you can help: I do inspection work on submarines that must be documented. Each Boat has it own ID code that I would like to appear in another area of the form based on what boat I select from a Form filed drop down list. |
#3
|
|||
|
|||
Say your Dropdown is bookmarked "Name" and yoru text field for the Unit Identification Code is bookmarked "UIC." You need to set a macro to run on exit from the DD.
Sub NameDDOnExit() Dim oFF As FormFields Set oFF = ActiveDocument.FormFields Select Case oFF("Name").Result Case "TOPEKA" oFF("UIC").Result = "12345" Case "PASADENA" oFF("UIC").Result = "54321" Case "HELENA" oFF("UIC").Result = "99999" End Select End Sub |
#4
|
|||
|
|||
Thank you very much for your help I got it to work perfectly. Can you help further?
This will help accuracy in our shop a great deal. For a check box what would the commands look like? For the VT/DIM box to be checked in block 10 the first form field in block 11 would say 1C |
#5
|
|||
|
|||
First let me say that I know how much submariners love to be inspected so perhaps I shouldn't do more to make it easier on your shop .
That said, I also know that submariners don't always appreciate what is best for them so: The first thing you need to do is to assign meaningful bookmark names to your formfields. Continuing from the previous example, lets name the checkbox VT_DIM and the text field B11_1 (That is for block 11, field 1 and perhaps not so meaningful). You could simply create another OnExit macro specifically for the checkbox, but if this is something you want to fully exploit then you should use a single OnExit macro. Something like this: Sub FormFieldOnExit() Dim oFF As FormFields Set oFF = ActiveDocument.FormFields Dim pName As String pName = FieldID Select Case pName Case "Name" Select Case oFF(pName).Result Case "TOPEKA" oFF("UIC").Result = "12345" Case "PASADENA" oFF("UIC").Result = "54321" Case "HELENA" oFF("UIC").Result = "99999" End Select Case "VT_DIM" Select Case oFF("VT_DIM").CheckBox.Value Case "True" oFF("B11_1").Result = "1C" Case Else oFF("B11_1").Result = "" End Select End Select End Sub Function FieldID() As String Dim pFldName As String If Selection.FormFields.Count = 1 Then pFldName = Selection.FormFields(1).Name ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then pFldName = Selection.Bookmarks(Selection.Bookmarks.Count).Nam e End If FieldID = pFldName End Function |
#6
|
|||
|
|||
Thank you for your help... I am about to step out to do another inspection. I do not inspect submariners often, but rather those that repair and replace corroded components...it is amazing what the saltwater does to steel once it is exposed by chipped paint.
I will let you know how the next upgrade goes... thank you for your help. |
#7
|
|||
|
|||
Got an error I hope you can help....
Im getting Case without select errors and case without select... Would these be better off as separate macros as the first one is functional if I delete the items I added in the check box value areas. I included an updated attachment and you can see the marco below... Form ending in B has the bad macro, none-B form has only the first macro with not checkbox name changes And if this works I would like to also have the selection of the PT or MT box cause the selection of a box in 15 or 16 as applicable. If MT is selected the the last box in 15 and if PT is selected then the first box in 16 is selected. Also, using the machines local date I would like the second block of block 19 and 20 to use the PC's current date. Sub NameDDOnExit() Dim oFF As FormFields Set oFF = ActiveDocument.FormFields Select Case oFF("Name").Result Case "USS Florida SSGN-728" oFF("UIC").Result = "21038" Case "USS Georgia SSGN-729" oFF("UIC").Result = "21039" Case "USS Alaska SSBN-732" oFF("UIC").Result = "21042" Case "USS Tennessee SSBN-734" oFF("UIC").Result = "21044" Case "USS West Virginia SSBN-736" oFF("UIC").Result = "21365" Case "USS Maryland SSBN-738" oFF("UIC").Result = "21460" Case "USS Rhode Island SSBN-740" oFF("UIC").Result = "21682" Case "USS Wyoming SSBN-742" oFF("UIC").Result = "21846" Case "TRF" oFF("UIC").Result = "44466" Case "Triper" oFF("UIC").Result = "00024" Case "CSS-20" oFF("UIC").Result = "63976" Case " " oFF("UIC").Result = " " End Select Case "VT_DIM" Select Case oFF("VT_DIM").CheckBox.Value Case "True" oFF("B11_1").Result = "1C" Case Else oFF("B11_1").Result = "" Case "PT" Select Case oFF("PT").CheckBox.Value Case "True" oFF("B11_2").Result = "4E" Case Else oFF("B11_2").Result = "" Case "MT" Select Case oFF("MT").CheckBox.Value Case "True" oFF("B11_3").Result = "3G" Case Else oFF("B11_3").Result = "" End Select End Select End Sub |
#8
|
|||
|
|||
You have to be careful when constructing case statements or you will generate errors.
I do this sort of thing for a living now, so I can't continue to build your form for you for free. Attached is a working document. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Text Wrapping on Fixed Lines in a Form field/Table cell | okrmjr | Word Tables | 0 | 10-30-2009 08:52 AM |
Outlook 2007, contacts: drop down in custom field | pacecal | Outlook | 0 | 06-16-2009 10:43 AM |
Text Form Field formatting problem | Toshii | Word | 1 | 06-08-2009 07:21 PM |
How can I fill in form I received in email that used underlines instead of text field | Gail L. | Word | 2 | 05-17-2009 12:38 PM |
evaluating a text expression in a form field | gwp1 | Word | 0 | 10-08-2007 02:15 PM |