Prev: welcome to windows7
Next: ComboBox text Limit
From: johnnykunst on 22 Apr 2010 04:34 I have the following macro which works great to make a form drop down list mandatory to fill in: Sub MustFillIn() If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then Do sInFld = InputBox("This field must be filled in, fill in below.") Loop While sInFld = "" ActiveDocument.FormFields("nameDD").Result = sInFld End If End Sub However, the user is free to enter whatever they want in the input box, although the field this fires from if nothing is entered is a drop down- is there any way to make the input box that pops up contain the same list as the actual drop down on the form? --- frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general/
From: Graham Mayor on 22 Apr 2010 05:37 You can force the user to fill in the field by using a macro on exit from the field and another on entry to any other field the user might select. The macros are aonexit and aonentry and the principles are covered at http://www.gmayor.com/formfieldmacros.htm Option Explicit Public rngFF As Word.Range Public fldFF As Word.FormField Public mstrFF As String Public Sub AOnExit() With GetCurrentFF If .Type = wdFieldFormDropDown Then If .Result = "ENTER NAME" Then MsgBox "You must make a selection"" End If End If mstrFF = GetCurrentFF.name End With End Sub Public Sub AOnEntry() If ActiveDocument.FormFields(mstrFF).Result = "ENTER NAME" Then ActiveDocument.FormFields(mstrFF).Select mstrFF = vbNullString End If End Sub Public Function GetCurrentFF() As Word.FormField Set rngFF = Selection.Range rngFF.Expand wdParagraph For Each fldFF In rngFF.FormFields Set GetCurrentFF = fldFF Exit For Next End Function -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "johnnykunst" <user(a)msgroups.net/> wrote in message news:ua7yhaf4KHA.3880(a)TK2MSFTNGP04.phx.gbl... >I have the following macro which works great to make a form drop down list >mandatory to fill in: > > Sub MustFillIn() > If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then > Do > sInFld = InputBox("This field must be filled in, fill in > below.") > Loop While sInFld = "" > ActiveDocument.FormFields("nameDD").Result = sInFld > End If > End Sub > > However, the user is free to enter whatever they want in the input box, > although the field this fires from if nothing is entered is a drop down- > is there any way to make the input box that pops up contain the same list > as the actual drop down on the form? > > > --- > frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general/
From: johnnykunst on 23 Apr 2010 02:12 The trouble is the user may not even enter or exit the form field at all, in which case that macro wouldn't work. The macro I posted is inserted into a different macro I have which automates the save process, and is linked to specified fields- it works fine for text entries, but for drop downs, because the input box is free text, the user can input anything they want, rather than only the actual items in the drop down, so what I want to do is have the input box only give the drop downs as possible inputs. --- frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general/Word-2003-VBA-to-limit-options-in-Inputbox-to-those-in-drop-d
From: johnnykunst on 24 Apr 2010 03:21 So basically, I need a macro that will check a specified drop down entry and if it contains "ENTER NAME" it will pop up an input box with just the options on the original drop down available to be input & this would not be dependant on the user clicking in or out of the field. --- frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general/Word-2003-VBA-to-limit-options-in-Inputbox-to-those-in-drop-d
From: Graham Mayor on 24 Apr 2010 05:20
If you apply the AOnEntry macro to all the fields and the AOnExit macro to the dropdown field, the user will not be able to complete the form until a selection is made from the dropdown. The following macro will apply the AOnEntry macro to all the fields Public Sub SetupMacros() Dim ffItem As Word.FormField For Each ffItem In ActiveDocument.FormFields ffItem.EntryMacro = "AOnEntry" Next End Sub Even better, get rid of the dropdown field altogether and setup a userform to get the required user input and send the result to a docvariable which you can display in the document with a docvariable field - or send it to a text form field. In the case of the latter consider a userform with a list box, a label and a command button and on the document a text form field to take the result. The example uses default names, but you can (and should) change those. Call the userform from an AutoNew macro in the form template eg Sub AutoNew() UserForm1.Show End Sub and the userform will display when a new form is created from the template. The form won't let the user cancel, or proceed until a value is entered in the list box. The form code could be Option Explicit Private Sub UserForm_Initialize() Me.Caption = "Select name & click Next" Me.CommandButton1.Caption = "Next" With Me.Label1 .Caption = "" .ForeColor = wdColorRed .TextAlign = fmTextAlignCenter .Font.Size = "14" End With With Me.ListBox1 .Clear .AddItem " " .AddItem "Fred" .AddItem "Bill" .AddItem "John" .AddItem "Susan" .ListIndex = 0 End With End Sub Private Sub CommandButton1_Click() If Me.ListBox1.Value = " " Then Me.Label1.Caption = "You must select a name!" UserForm1.Repaint Exit Sub End If ActiveDocument.FormFields("Text1").Result = Me.ListBox1.Value Unload Me End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then Cancel = True CommandButton1_Click End If End Sub -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "johnnykunst" <user(a)msgroups.net/> wrote in message news:e5h9B734KHA.1888(a)TK2MSFTNGP05.phx.gbl... > So basically, I need a macro that will check a specified drop down entry > and if it contains "ENTER NAME" it will pop up an input box with just the > options on the original drop down available to be input & this would not > be dependant on the user clicking in or out of the field. > > --- > frmsrcurl: > http://msgroups.net/microsoft.public.word.vba.general/Word-2003-VBA-to-limit-options-in-Inputbox-to-those-in-drop-d |