Can I create a drop down list that will let me select an item 
Author Message
 Can I create a drop down list that will let me select an item

I'm not sure if this VBA related, and apologise if it appears off-topic.

I have a template for a report that is produced every week.
I would like to customise it where a drop down list will appear on a page of
the document, allowing the editor of the report to select a desired string
of text. Is there any way to doing this?

D.Dawson



Mon, 07 Nov 2005 17:12:42 GMT  
 Can I create a drop down list that will let me select an item
I'm not sure if this VBA related, and apologise if it appears off-topic.

I have a template for a report that is produced every week.
I would like to customise it where a drop down list will appear on a page of
the document, allowing the editor of the report to select a desired string
of text. Is there any way to doing this?

D.Dawson



Mon, 07 Nov 2005 18:33:47 GMT  
 Can I create a drop down list that will let me select an item
Dylan,

See:

Please Fill Out This Form
Part 1: Create professional looking forms in Word
http://www.computorcompanion.com/LPMArticle.asp?ID=22

Part 2: Adding Automation to your Word forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=46

Part 3: Learn more VBA (macros) to automate your forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=119

Part 4: Use custom dialog boxes in your Word forms
http://www.computorcompanion.com/LPMArticle.asp?ID=127

Part 5: Connect your AutoForm to a database to save input time and keep
better records!
http://www.computorcompanion.com/LPMArticle.asp?ID=136

If you wanted to use autotext to store the string, you could use the
following routine in conjunction with a formfield type dropdown

' Macro created 15-11-97 by Doug Robbins to add the address corresponding to
a drop down name

'

Set myDrop = ActiveDocument.FormFields("Dropdown1").DropDown

Company = myDrop.ListEntries(myDrop.Value).Name

Address = ActiveDocument.AttachedTemplate.AutoTextEntries(Company).Value

ActiveDocument.FormFields("Text1").Result = Address

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:

> I'm not sure if this VBA related, and apologise if it appears off-topic.

> I have a template for a report that is produced every week.
> I would like to customise it where a drop down list will appear on a page
of
> the document, allowing the editor of the report to select a desired string
> of text. Is there any way to doing this?

> D.Dawson



Mon, 07 Nov 2005 19:39:44 GMT  
 Can I create a drop down list that will let me select an item
G'day "Dylan" <- ->,

a general answer to a general question - probably.

You could use special styles and the autotext list feature as well.

Need more info to go on here bro :-)

 "Dylan" <- -> was spinning this yarn:

Quote:
>I'm not sure if this VBA related, and apologise if it appears off-topic.

>I have a template for a report that is produced every week.
>I would like to customise it where a drop down list will appear on a page of
>the document, allowing the editor of the report to select a desired string
>of text. Is there any way to doing this?

>D.Dawson

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.

Products:   http://www.geocities.com/word_heretic/products.html
Spellbooks: 735 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.



Mon, 07 Nov 2005 21:15:53 GMT  
 Can I create a drop down list that will let me select an item
Be aware that all of Doug's references are for "protected" forms. If your
template is not for a protected form already, you can use an AutoTextList field
and not have to protect the template. See
http://www.mvps.org/word/FAQs/TblsFldsFms/AutoTextList.htm for information.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Dylan,

> See:

> Please Fill Out This Form
> Part 1: Create professional looking forms in Word
> http://www.computorcompanion.com/LPMArticle.asp?ID=22

> Part 2: Adding Automation to your Word forms.
> http://www.computorcompanion.com/LPMArticle.asp?ID=46

> Part 3: Learn more VBA (macros) to automate your forms.
> http://www.computorcompanion.com/LPMArticle.asp?ID=119

> Part 4: Use custom dialog boxes in your Word forms
> http://www.computorcompanion.com/LPMArticle.asp?ID=127

> Part 5: Connect your AutoForm to a database to save input time and
> keep better records!
> http://www.computorcompanion.com/LPMArticle.asp?ID=136

> If you wanted to use autotext to store the string, you could use the
> following routine in conjunction with a formfield type dropdown

> ' Macro created 15-11-97 by Doug Robbins to add the address
> corresponding to a drop down name

> '

> Set myDrop = ActiveDocument.FormFields("Dropdown1").DropDown

> Company = myDrop.ListEntries(myDrop.Value).Name

> Address =
> ActiveDocument.AttachedTemplate.AutoTextEntries(Company).Value

> ActiveDocument.FormFields("Text1").Result = Address

> Please respond to the newsgroups for the benefit of others who may be
> interested.

> Hope this helps
> Doug Robbins - Word MVP


>> I'm not sure if this VBA related, and apologise if it appears
>> off-topic.

>> I have a template for a report that is produced every week.
>> I would like to customise it where a drop down list will appear on a
>> page of the document, allowing the editor of the report to select a
>> desired string of text. Is there any way to doing this?

>> D.Dawson



Tue, 08 Nov 2005 00:42:17 GMT  
 Can I create a drop down list that will let me select an item
Both of these are good, but not exactly what I'm looking for. I apologise
for not supplying more information to start with.

I have a blank summary sheet, which is basically a table, and this is to be
added to the back of reports. Then the summary items will be added to it. As
it stands just now, the top of the sheet has a text box in which the
reference number of the report is usually typed. And, I am looking for a way
to do this mechanically.

Regards Dylan



Tue, 08 Nov 2005 18:02:33 GMT  
 Can I create a drop down list that will let me select an item

Quote:
> Both of these are good, but not exactly what I'm looking for. I apologise
> for not supplying more information to start with.

> I have a blank summary sheet, which is basically a table, and this is to
be
> added to the back of reports. Then the summary items will be added to it.
As
> it stands just now, the top of the sheet has a text box in which the
> reference number of the report is usually typed. And, I am looking for a
way
> to do this mechanically.

So, I thought creating a listbox of all the references that we use in my
company would work. However, I cannot have a locked document and the list
must be easy to scroll through, because it contains a couple of hundred
entries.
Quote:

> Regards Dylan



Tue, 08 Nov 2005 18:56:16 GMT  
 Can I create a drop down list that will let me select an item
Hi Dylan,

In that case, I would be using a userform with a multicolumn listbox that is
populated with data that is stored in an external file.

See the article How to create a Userform at:

http://www.mvps.org/word/FAQs/Userforms/CreateAUserForm.htm

Here's an example of a routine that loads a listbox with client details
stored in a table in a separate
document (which makes it easy to maintain with additions, deletions etc.),
that document being saved as Clients.Doc for the following code.

On the UserForm, have a list box (ListBox1) and a Command Button
(CommandButton1) and use the following code in the UserForm_Initialize() and
the CommandButton1_Click() routines

Private Sub UserForm_Initialize()
    Dim sourcedoc As Document, i As Integer, j As Integer, myitem As Range,
m As Long, n As Long
    ' Modify the path in the following line so that it matches where you
saved Suppliers.doc
    Application.ScreenUpdating = False
    ' Open the file containing the client details
    Set sourcedoc = Documents.Open(FileName:="e:\worddocs\Clients.doc")
    ' Get the number or clients = number of rows in the table of client
details less one
    i = sourcedoc.Tables(1).Rows.Count - 1
    ' Get the number of columns in the table of client details
    j = sourcedoc.Tables(1).Columns.Count
    ' Set the number of columns in the Listbox to match
    ' the number of columns in the table of client details
    ListBox1.ColumnCount = j
    ' Define an array to be loaded with the client data
    Dim MyArray() As Variant
    'Load client data into MyArray
    ReDim MyArray(i, j)
    For n = 0 To j - 1
        For m = 0 To i - 1
            Set myitem = sourcedoc.Tables(1).Cell(m + 2, n + 1).Range
            myitem.End = myitem.End - 1
            MyArray(m, n) = myitem.Text
        Next m
    Next n
   ' Load data into ListBox1
    ListBox1.List() = MyArray
    ' Close the file containing the client details
    sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

Private Sub CommandButton1_Click()
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
    ListBox1.BoundColumn = i
    Addressee = Addressee & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Addressee").Range.InsertAfter Addressee
UserForm2.Hide
End Sub

The Initialize statement will populate the listbox with the data from the
table and then when a client is selected in from the list and the command
button is clicked, the information for that client will be inserted into a
bookmark in the document.  You may want to vary the manner in which it is
inserted to suit our exact requirements, but hopefully this will get you
started.

To make it easy for you, the code has been written so that it will deal with
any number of clients and any number of details about each client.  It
assumes that the first row of the table containing the client details is a
header row.

--
Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:

> > Both of these are good, but not exactly what I'm looking for. I
apologise
> > for not supplying more information to start with.

> > I have a blank summary sheet, which is basically a table, and this is to
> be
> > added to the back of reports. Then the summary items will be added to
it.
> As
> > it stands just now, the top of the sheet has a text box in which the
> > reference number of the report is usually typed. And, I am looking for a
> way
> > to do this mechanically.

> So, I thought creating a listbox of all the references that we use in my
> company would work. However, I cannot have a locked document and the list
> must be easy to scroll through, because it contains a couple of hundred
> entries.

> > Regards Dylan



Tue, 08 Nov 2005 19:43:53 GMT  
 Can I create a drop down list that will let me select an item
Sory for the delay in getting back to you, I got disconnected there, for a
while.

Anyways, this example is what I am looking for, the external file holds all
the references for the projects, my only reservation is that on an old
computer the external file takes a while to load.

I would like to reference to an access database rather than a word file.
Also,
how do I invoke the userform when the file is inserted to another document?

Somethingh along the lines of...

Private Sub Document_Inserted()
    frmContractorList.Show
End Sub

Where I would use
Private Sub Document_New()
when a new document is created, the document I want to use has to be
inserted into another.

Yours
Dylan Dawson



Sat, 19 Nov 2005 15:21:43 GMT  
 Can I create a drop down list that will let me select an item
Hi Dylan,

The following routing populates a Listbox with data from a table in an
Access database:

Private Sub UserForm_Initialize()
'allocate memory for the database object as a whole and for the active
record
Dim myDataBase As Database
Dim myActiveRecord As Recordset
Dim i As Integer, j As Integer, m As Integer, n As Integer
'Open a database
Set myDataBase = OpenDatabase("E:\Access97\Ely\ResidencesXP.mdb")
'Access the first record from a particular table
Set myActiveRecord = myDataBase.OpenRecordset("Owners", dbOpenForwardOnly)
'Get the number of fields in the table
j = myActiveRecord.Fields.Count
'Get the number of Records in the table
'Loop through all the records in the table until the end-of-file marker is
reached
i = 0
Do While Not myActiveRecord.EOF
    i = i + 1
    'access the next record
    myActiveRecord.MoveNext
Loop
myActiveRecord.Close
'Set the number of columns in the listbox
ListBox1.ColumnCount = j
' Define an array to be loaded with the data
Dim MyArray() As Variant
'Load data into MyArray
ReDim MyArray(i, j)
For n = 0 To j - 2
    Set myActiveRecord = myDataBase.OpenRecordset("Owners",
dbOpenForwardOnly)
    m = 0
    Do While Not myActiveRecord.EOF
        MyArray(m, n) = myActiveRecord.Fields(n + 1)
        m = m + 1
    myActiveRecord.MoveNext
    Loop
Next n
' Load data into ListBox1
ListBox1.List() = MyArray
'Then close the database
myActiveRecord.Close
myDataBase.Close
End Sub

In order for this code to run, you must establish a reference, in your
template, to Microsoft DAO #.## Object Library.  To do this, open the VB
editor and choose References on the Tools menu.   The numbers #.## will vary
with your version of Word, maybe 3.51 or 3.60

I would suggest that the simplest thing to do is have a template with the
userform in it and the table into which the data from the list box will be
inserted.  Then do a File>New to create a document from that template
containing a table with the data for the report that you are working on,
then copy that table and paste it into your report.  The copying of the
table to the clipboard could be done via the code in the userform so that
then all you would have to do would be go to the location in the report
where you want the information and press Ctrl+V.  The code in the userform
could also close the document that was created without saving it.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:

> Sory for the delay in getting back to you, I got disconnected there, for a
> while.

> Anyways, this example is what I am looking for, the external file holds
all
> the references for the projects, my only reservation is that on an old
> computer the external file takes a while to load.

> I would like to reference to an access database rather than a word file.
> Also,
> how do I invoke the userform when the file is inserted to another
document?

> Somethingh along the lines of...

> Private Sub Document_Inserted()
>     frmContractorList.Show
> End Sub

> Where I would use
> Private Sub Document_New()
> when a new document is created, the document I want to use has to be
> inserted into another.

> Yours
> Dylan Dawson



Sat, 19 Nov 2005 17:46:30 GMT  
 Can I create a drop down list that will let me select an item
Hi Doug,

I get a bit confused at the line;
For n = 0 To j - 2

Why have "j - 2" ?

Extracted from your original code:
'Load data into MyArray
ReDim MyArray(i, j)
For n = 0 To j - 2
    Set myActiveRecord = myDataBase.OpenRecordset("Owners",
dbOpenForwardOnly)
    m = 0
    Do While Not myActiveRecord.EOF
        MyArray(m, n) = myActiveRecord.Fields(n + 1)
        m = m + 1
    myActiveRecord.MoveNext
    Loop
Next n



Tue, 22 Nov 2005 16:53:16 GMT  
 Can I create a drop down list that will let me select an item
Hi Dylan,

I guess in the situation where I was using that code, I didn't want the last
field loaded into the list box (though I did have the listbox.coumncount set
to the number of fields in the table.

Change it to j - 1 to get all of the fields in your table.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:

> Hi Doug,

> I get a bit confused at the line;
> For n = 0 To j - 2

> Why have "j - 2" ?

> Extracted from your original code:
> 'Load data into MyArray
> ReDim MyArray(i, j)
> For n = 0 To j - 2
>     Set myActiveRecord = myDataBase.OpenRecordset("Owners",
> dbOpenForwardOnly)
>     m = 0
>     Do While Not myActiveRecord.EOF
>         MyArray(m, n) = myActiveRecord.Fields(n + 1)
>         m = m + 1
>     myActiveRecord.MoveNext
>     Loop
> Next n



Tue, 22 Nov 2005 17:51:49 GMT  
 
 [ 19 post ]  Go to page: [1] [2]

 Relevant Pages 

1. X-Posted: Can I create a drop down list that will let me select an item

2. dynamically change a html form when a user select an item from a drop down list

3. Press F1 key while drop-down menu item highlighted, drop-down menu stays on top

4. Drop Down List Box - Drop Down portion does not always disappear after Click event

5. Trouble retrieving selected drop-down item

6. Drop-down Listbox - programatically setting the selected item

7. Multi-select drop down list

8. Multi-select drop down list?

9. Selecting Access column into drop down list

10. Multi-Select Drop Down List Box

11. Open drop-down list in select box

12. Drop Down List Select without Submit Button - How?

 

 
Powered by phpBB® Forum Software