Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Apr 2004
    Location
    Durham, North Carolina, USA
    Posts
    32
    Thanks
    11
    Thanked 1 Time in 1 Post

    Form to let user choose a template

    Hi folks,

    I have a Word 2007 procedure to produce incrementally-numbered documents (in this case, test requisition forms) from a specific template. That solution has worked great, but we've just added new customers and now I need to produce them from different templates.

    I'd like to present my user with a form prompting them to choose the template they want (probably as a combo box). How would I populate the combo to display the template list? Ideally it would only show a specific subset (the ones which can be used to create the test requisitions), but I'd settle for the whole list.

    Thanks in advance,

    Beej
    Last edited by Beej; 2013-04-09 at 16:09. Reason: added application and version info

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    I would do this by creating a series of building blocks in a single template. Each building block would be a different version of the test req form. Then I would create a userform with the combo box populated by reading through the list of building blocks available in the template. If you had other forms then you could modify the code to just show a specific type of building block (ie different form type).

    This post shows you you might fill the combo box with the BuildingBlock names
    http://windowssecrets.com/forums/sho...l=1#post887200
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    Beej (2013-04-10)

  4. #3
    Lounger
    Join Date
    Apr 2004
    Location
    Durham, North Carolina, USA
    Posts
    32
    Thanks
    11
    Thanked 1 Time in 1 Post
    Andrew,

    Thanks. Since I'd already created a couple of templates--and I don't like working with building blocks --I searched the web for a way to populate the combo box with the template names. For completeness, in case anyone else has a similar need, here's what I found:

    Code:
    Private Sub UserForm_Initialize()
        
        'Files in folder listed in cboTemplateName
        
        Dim FSO As Object, fld As Object, Fil As Object
        Dim SubFolderName As String
        Dim i As Integer
        
        Set FSO = CreateObject("Scripting.FileSystemObject")
        
        Me.cboTemplateName.Clear 'clear previous entries
        SubFolderName = "C:\Documents and Settings\bwitkin\Application Data\Microsoft\Templates\Test Requisitions"
        
        Set fld = FSO.GetFolder(SubFolderName)
        
        For Each Fil In fld.Files
            
            i = i + 1
            Me.cboTemplateName.AddItem Fil.Name 'Populate combo with names of files in folder
             
        Next Fil
         
    End Sub
    It took some work after that--the file names include the extensions, which cause a Run-time error, and because the templates in question were in a sub-folder I had to give the full path to the code which created the documents. Still, it worked and I learned some new things.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •