Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

populate combobox from table and vice versa

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
darkhorizon2002@yahoo.com - 27 Jan 2007 06:28 GMT
Hi Everyone,

I'm using one combo box to populate another combobox.  I'm extracting
the data from a word table where column A of the table goes to cb1 and
based on that selection column B of the row in cb1 goes to cb2.

However, I've hit a wall when there is more than one of the same name
in cb1.  I would like to know if it's possible to populate cb2 with the
data of all the rows which match the name?

For example, if in cb1 the name selected is "Kraft Foods" and on the
table in column A there are 3 rows for "Kraft foods" where each row in
column B reads "Mary Biggs, Tanya Heller and Mica Ripa respectively"is
it possible  for cb2 to pull data from column B of the table for each
name  matching the name in cb1?

company          name
Kraft Foods       Mary Biggs
Kraft Foods     Tanya Heller
Kraft Foods       Mica Ripa

At the present what it's doing is populating cb1 with 3 Kraft Foods and
in cb2 pulling the name in column B for the row based on which "Kraft
Foods" you select in cb1 (it's hard to tell which person I'm selecting
this way)

Also, I would like to populate the table using the data typed in cb1
and cb2 by the user if name is not available.

here's what I have:

Dim sourcedoc As Document, i As Long, myitem As Range, myitem2 As Range
Application.ScreenUpdating = False
Set sourcedoc = Documents.Open(FileName:="C:\Documents and Settings\My
Documents\client.doc")
For i = 2 To sourcedoc.Tables(1).Rows.Count
   Set myitem = sourcedoc.Tables(1).Cell(i, 1).Range
   Set myitem2 = sourcedoc.Tables(1).Cell(i, 2).Range
   myitem.End = myitem.End - 1
   cmb1.AddItem myitem.Text
   cmb2.AddItem  myitem2.Text
  Next i
Application.ScreenUpdating = True
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges

thank you.
Greg Maxey - 27 Jan 2007 07:28 GMT
As far as I know the answer to your first question is no.  The way you
are going about it that is.

First of all from the code you have provided, what is displayed in
combobox2 has nothing to do with what the user selected in combobox1.
Is your completed code a state secret that you couldn't share?

Why does your column 1 list Kraft Foods 3 times.  If your users is
expected to pick something why would you provide that something three
times in the same list.  You will find a method for doing something
very similiar to what I think you want to do here:

http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm

look under the subheading "Cascading ListBoxes"

As to the second part of your question I don't know.  If it is
possible, at first glanc it appears that it would take some
considerable coding and it is too late at night for that now.

Good luck.

On Jan 27, 1:28 am, darkhorizon2...@yahoo.com wrote:
> Hi Everyone,
>
[quoted text clipped - 42 lines]
>
> thank you.
darkhorizon2002@yahoo.com - 28 Jan 2007 04:05 GMT
Hi Greg,

No state secret....just forgot...here is the other portion

Private Sub cmb2_Change()
Dim sourcedoc As Document, i As Long, myitem As Range, myitem2 As
Range, myitem3 As Range,
Set sourcedoc = Documents.Open(FileName:="C:\Documents and Settings\My
Documents\client.doc")
Set myitem = sourcedoc.Tables(1).Cell(cmb1.ListIndex + 2, 3).Range
Set myitem2 = sourcedoc.Tables(1).Cell(cmb1.ListIndex + 2, 4).Range
Set myitem3 = sourcedoc.Tables(1).Cell(cmb1.ListIndex + 2, 5).Range
txt2.Value = myitem
txt3.Value = myitem2
txt4.Value = myitem3
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

as for the reason "kraft foods" appears 3 times is because there are 3
different reps for Kraft foods.  I would like to fix the code if
possible so that cb1 shows the company  and cb2 selects all members of
that company.  Is this possible or am I wasting my time?

Thank you.

> As far as I know the answer to your first question is no.  The way you
> are going about it that is.
[quoted text clipped - 66 lines]
>
> > thank you.- Hide quoted text -- Show quoted text -
Greg Maxey - 28 Jan 2007 04:37 GMT
If you want to show one combobox that list Kraft Foods, and a second that
lists the reps associated with Kraft foods then it is possible and the
website I referred you to will show you how.

If you want to show one combobox last list Kraft foods three time and the
second that shows the reps associated with Kraft foods (the same reps
regardless of which one of the three Kraftfoods entries the user picks in
the first combobox)  ... well yes that is possible too, but why you would
want to do that I still don't understand.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Greg,
>
[quoted text clipped - 92 lines]
>>
>>> thank you.- Hide quoted text -- Show quoted text -
darkhorizon2002@yahoo.com - 28 Jan 2007 05:19 GMT
Greg

i'd rather not use a listbox because it limits you from entering free
data.  The reason I've used a combobox is to have the option of
selecting or entering data if name is not found.  All I'm looking to
do at this point is do a match if the name in column one of the table
where the combobox (cb1) pulls its data is listed more than once then
cb2 should pull all the reps (in column 2 of the table ) associated
with the name in cb1 and cb1 should show the name once not 3 times.

> If you want to show one combobox that list Kraft Foods, and a second that
> lists the reps associated with Kraft foods then it is possible and the
[quoted text clipped - 108 lines]
>
> >>> thank you.- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Greg Maxey - 28 Jan 2007 05:46 GMT
I am fairly certain that with minor adjustments the method I show for a
listbox will work for a combobox.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greg
>
[quoted text clipped - 126 lines]
>>>>> thank you.- Hide quoted text -- Show quoted text -- Hide quoted
>>>>> text -- Show quoted text -
darkhorizon2002@yahoo.com - 28 Jan 2007 05:53 GMT
Greg,

Ok...I'll give it a whirl and let you know how it turns out.  Thanks
again for your patience and feedback.

> I am fairly certain that with minor adjustments the method I show for a
> listbox will work for a combobox.
[quoted text clipped - 135 lines]
> >>>>> thank you.- Hide quoted text -- Show quoted text -- Hide quoted
> >>>>> text -- Show quoted text -- Hide quoted text -- Show quoted text -
darkhorizon2002@yahoo.com - 28 Jan 2007 06:29 GMT
Hi Greg,

made some modifications and it works wonderfully...thank you so much
for lending me your expertise as well as excercising some patience to
guide me through.

On Jan 28, 12:53 am, darkhorizon2...@yahoo.com wrote:
> Greg,
>
[quoted text clipped - 140 lines]
> > >>>>> thank you.- Hide quoted text -- Show quoted text -- Hide quoted
> > >>>>> text -- Show quoted text -- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Greg Maxey - 28 Jan 2007 06:41 GMT
Glad I could help.  Expertise ?... All I contribute is what others have
shown me or things that I have tripped over ;-)

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Greg,
>
[quoted text clipped - 163 lines]
>>>>>>>> text -- Show quoted text -- Hide quoted text -- Show quoted
>>>>>>>> text -- Hide quoted text -- Show quoted text -

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.