Re: autofill of a textbox from a listbox selection

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



What sort of Checkboxes are we talking about? If of the type as used in a
protected document, you could use a macro that runs on Exit from the first
Checkbox to set the value of the second

With ActiveDocument
.FormFields("Check2").CheckBox.Value =
..FormFields("Check1").CheckBox.Value
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"John Viall" <JohnViall@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9BF12481-CC3A-4666-954C-C70ED9CE42F4@xxxxxxxxxxxxxxxx
That worked great, now how would I go about using Words built-in Checkbox
to
do the following:
When I select chkBox1, and mark the "X", it will automatically go down
further into the document and select chkBox2 and also mark it.

Thanks,
John

"Doug Robbins - Word MVP" wrote:

Use a variation of this 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 Clients.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.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"John Viall" <JohnViall@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1E1A2D18-8729-442C-8CDA-03D3DB9EF926@xxxxxxxxxxxxxxxx
I'm trying to do the same thing, however, I want to make a selection
from
a
listbox, and have it autopopulate several locations in a form, with
different
information.

For instance, I want to select a Company Name, and have it autopopulate
at
different locations on the form, the Address, Phone Number, and Contact
Person.

How can I do this?

Thanks, and sorry for hijacking this discussion.

John

"Scott Noles" wrote:

To help clarify for everyone so we are all on the same page. This
would
be a
protected Word document. What I am looking to do is take a ListBox of
four
sites and based upon the selection of one of the 4 sites I would like
a
textbox to be filled with the address.

Site 1
Site 2
Site 3
Site 4

Site 1 address
123 Any Street
Home Town, State 12345

Site 2 Address
345 My Street
Other town, State 54323

Site 3 address
876 This street
Town, State 34342

Site 4 Address
124 Ave
City, State 12454

Once I select the site from the listbox then the text with the correct
address is inserted. My assumption is the Macro that I am creating
would
have to run on exit from the listbox. I hope this clarifies.





"Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx> wrote in message
news:OCYfHEnDHHA.4060@xxxxxxxxxxxxxxxxxxxxxxx
It is not clear what type of form you are talking about, but I am
assuming
that it is one using formfields in a protected document. If that is
the
case, if you store the address details for each site as autotext,
with
the
name of each autotext entry corresponding to the site name and then
you
have the sites in a dropdown type formfield, then the following code
run
on exit from that formfield will do what you want:

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

'

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

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

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

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


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Scott Noles" <Scott_Noles@xxxxxxxxxxxxxxxx> wrote in message
news:E83EEB0D-4A48-4529-8ABF-4CCB45212175@xxxxxxxxxxxxxxxx
Hello All,

I am new to this group and I do not see my question on the list of
items.
I am currently working on creating a Word Template to be used by an
administrative assistant to help complete meeting communication.
This
template has a listbox that includes the location of 4 meeting
sites.
I
would like the administrative assistant to be able to select one of
the
sites and have the macro fill a textbox with that site's address
and
phone number. The macro would run on exit of the listbox. I have
not
worked with the VBA editor yet so any advice would be great.

Thank you.








.


Quantcast