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 / October 2006

Tip: Looking for answers? Try searching our database.

Dynamic Array - Combo Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mmouse1466 - 29 Sep 2006 16:53 GMT
I am creating a user form with combo selection boxes.  One of my combo boxes
has a selection that is greater than the 25 items so I created a dynamic
array with using VB for the info lookup. So when the using goes to this combo
box it opens up a VB userform that has 3 combo boxes on it.

The array has 4 columns (column 1 = index number, column 2 = Port, column 3
= Crossing, column 4 = Terminal) and 650 rows.  

I have it set up so when I select the Port  "Atlanta" it shows in the next
combo box only the crossings associated with "Atlanta"  say "Charleston" and
then the third Combo box only shows the terminals assoicated with
"Charleston".  

Each combo box shows the appropriate associated info, but my problem is that
it also shows blank lines where other info would normally be in the array.  
Is there a way to say not to show those blank lines?  Or should I set up my
array differently?

A sample of my code:

Dim Array_Main(651, 4)
Dim Array_FO(21)
Dim Array_Port(651)
Dim Array_Term(651)

Private Sub cbo_Terminal_Change()
       ActiveDocument.FormFields("Crossing").Result = cbo_Terminal.Value
End Sub

Private Sub cbo_FieldOffice_Change()
   Erase Array_Port
   Erase Array_Term
   
   ActiveDocument.FormFields("FOData").Result = cbo_FieldOffice.Value
   
   Dim x, i
   
   i = 0
   
   holder = ""
   
   For x = LBound(Array_Main) To UBound(Array_Main)
       If Array_Main(x, 2) <> holder And cbo_FieldOffice.Text =
Array_Main(x, 1) Then
           Array_Port(i) = Array_Main(x, 2)
           i = i + 1
       End If
       holder = Array_Main(x, 2)
   Next
   
   cbo_Port.List() = Array_Port
End Sub

Private Sub cbo_Port_Change()
   Erase Array_Term
   
   ActiveDocument.FormFields("FOData").Result = cbo_FieldOffice & " - " &
cbo_Port.Value
   
   Dim x, i
   
   i = 0
   
   For x = LBound(Array_Main) To UBound(Array_Main) - 1
       If Array_Main(x, 2) = cbo_Port.Text Then
           Array_Term(i) = Array_Main(x, 3)
           i = i + 1
       End If
   Next
   cbo_Terminal.List() = Array_Term
End Sub

Private Sub CommandButton1_Click()

Unload Me

End Sub

Private Sub UserForm_Initialize()
Dim x, i, holder

'Make master array
'Field Office List
   Array_Main(0, 1) = "Atlanta"
   Array_Main(1, 1) = "Atlanta"
.......
   Array_Main(649, 1) = "Tucson"
   Array_Main(650, 1) = "Tucson"

'Port of Entry List
   Array_Main(0, 2) = "Atlanta"
   Array_Main(1, 2) = "Atlanta"
.......
   Array_Main(649, 2) = "Sasabe"
   Array_Main(650, 2) = "Tucson"

'Terminal List
   Array_Main(0, 3) = "Atlanta"
   Array_Main(1, 3) = "Atlanta Hartsfield-Jackson Int'l Airport"
.......
   Array_Main(649, 3) = "Sasabe"
   Array_Main(650, 3) = "Tucson Int'l Airport"

'make Field Office Array

   i = 0
   holder = ""
   
   For x = LBound(Array_Main) To UBound(Array_Main)
       If Array_Main(x, 1) <> holder Then
           Array_FO(i) = Array_Main(x, 1)
           i = i + 1
       End If
       holder = Array_Main(x, 1)
   Next x

   cbo_FieldOffice.List() = Array_FO

End Sub
Doug Robbins - Word MVP - 01 Oct 2006 20:15 GMT
See:

http://groups.google.com/group/microsoft.public.word.vba.userforms/browse_thread
/thread/f3f67faa8297aa66/bf86a5657fe2c34e?q=doug's+combo+box+code&rnum=1#bf86a56
57fe2c34e


Signature

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

>I am creating a user form with combo selection boxes.  One of my combo
>boxes
[quoted text clipped - 121 lines]
>
> End Sub
 
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.