View Full Version : Autofill Prompted From Drop Down List Selection
s2008979
04-02-2014, 12:52 AM
Hi guys, 
i am very new at this but am very keen on learning. Please be gentle...
I was wondering if i can create a form that autofills predefined values into the cells of a table upon Drop down lists selection. I have attached a mock up example of what I mean. 
Level Value* Comment*
Level 1 10 OK 
Level 2 20 Not bad
Level 3 30 Better
Level 4 40 Impressive 
Level 5 50 Perfect
*i would like these values to be autofilled upon selection of their corresponding Level. i.e. If Level 1 is selected then i would like the Value and Comment field to be autofilled with 10 and OK respectively. 
Thanks in advance for any help,
Michael 
11495
macropod
04-04-2014, 05:21 AM
See attached. The document uses dropdown content controls with a content control on-exit macro, which you can access via Alt-F11.
macropod
04-06-2014, 03:49 PM
snb: your code errors-out if the user selects the default text. Plus it outputs an unwanted '_' instead of a space in 'Not bad'. Back to the drawing board ... you have some basic issues to address
s2008979
04-06-2014, 04:51 PM
Incedible stuff. Thanks so much for your help. 
You have inspired me to skill up get a grip on the whole VBA thing. So far I have just finished watching some MSDN webinars and about to read some recomended material. It looks like a very step but rewarding learning curve. 
Michael
s2008979
04-06-2014, 08:02 PM
Paul, 
I kind of get it i think. Here is my newbie take on your code. 
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)          'I have not come across this sub naming before
     
Dim i As Long                                                             'Creating a vaiable i
With ContentControl.Range                                           'Defining the drop down list as a group
If .Information(wdWithInTable) = False Then Exit Sub        'Not to sure why an if statement is here.
i = .Cells(1).RowIndex                                                  'i is the first row in the selection. Why is "i" defined here and not under Dim above?
Select Case Split(.Text, " ")(1)                                      'Here is how you linked i to the drop down list range. Not exactly sure on this one.
  Case 1
    With .Tables(1).Rows(i)                                            'This identifies the selection made and enters the specified text.
      .Cells(2).Range.Text = 10
      .Cells(3).Range.Text = "OK"
    End With
macropod
04-06-2014, 08:46 PM
More like:
 Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) 'A built-in Document event macro.
 Dim i As Long ' Declare a numeric variable.
 With ContentControl.Range ' Define the range we're working with.
If .Information(wdWithInTable) = False Then Exit Sub ' We don't want to do anything with content controls that aren't in a table.
i = .Cells(1).RowIndex ' Get what table row we're on and populate the variable with it.
Split(.Text, " ")(1) ' Use the Split function to get the Level # from the Content Control.
Select Case Split(.Text, " ")(1)
 Case #  ' Use Select Case structure to process the Level #s.
 End Select
 With .Tables(1).Rows(i) ' Point to our table row.
 .Cells(2).Range.Text = ## ' Insert a number into the second cell in our row.
 .Cells(3).Range.Text = "??" ' Insert text into the third cell in our row.
 End With
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.