Results 1 to 3 of 3

Thread: Complicated Combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    1

    Complicated Combobox

    Good evening all,

    I'm new to visual basic so I thank anyone for whatever help you have for me. I am creating a form that runs on the opening of a Word template. The form takes the text in the fields and inserts them into their assigned bookmarks.

    What I am trying to do is create either a combobox item or split listing with a multiline string of text.

    For example,

    I would like the combobox to display as an option

    Jet1
    Jet2
    Jet3

    And when Jet1 is selected it would insert something similar to the below:

    Aircraft Aviation Business Jets Charter, LLC l Charter Services
    Chicago Sales Office l 6150 South Laramie Avenue l Chicago, IL 60638 l USA
    Tel. +1 773 581 9448 | +1 800 232 5388 l Fax +1 201 624 7338 l www.site.com

    I've tried tweaking the below code but I don't know how to break the text into multiple lines.

    Code:
    aStateList = Split(" AL AK AS AZ AR CA CO CT DE DC FM FL GA GU" _
                          & " HI ID IL IN IA KS KY LA ME MH MD MA MI MN MS" _
                          & " MO MT NE NV NH NJ NM NY NC ND MP OH OK OR PW" _
                          & " PA PR RI SC SD TN TX UT VT VI VA WA WV WI WY")
    Me.ComboBox1.List = aStateList
    End Sub
    Any help would be greatly appreciated. Thanks!

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Complicated Combobox

    you could...

    create an array of the data to be displayed
    then use the selected index in the combo to get the data from the array and do what you need with it.

    example
    Code:
    dim aryData()
    
    redim aryData(2,4)
    aryData(0,1)="Jet1"
    aryData(0,2)="Aircraft Aviation Business Jets Charter"
    aryData(0,3)="LLC l Charter Services
    Chicago Sales Office l 6150 South Laramie Avenue l Chicago, IL 60638 l USA"
    aryData(0,4)="Tel. +1 773 581 9448 | +1 800 232 5388 l Fax +1 201 624 7338"
    
    aryData(0,1)="Jet2"
    aryData(0,2)="Aircraft Aviation Business Jets Charter"
    aryData(0,3)="LLC l Charter Services
    Chicago Sales Office l 6150 South Laramie Avenue l Chicago, IL 60638 l USA"
    aryData(0,4)="Tel. +1 773 581 9448 | +1 800 232 5388 l Fax +1 201 624 7338"
    
    aryData(0,1)="Jet3"
    aryData(0,2)="Aircraft Aviation Business Jets Charter"
    aryData(0,3)="LLC l Charter Services
    Chicago Sales Office l 6150 South Laramie Avenue l Chicago, IL 60638 l USA"
    aryData(0,4)="Tel. +1 773 581 9448 | +1 800 232 5388 l Fax +1 201 624 7338"
    Then you can fill your combo like:
    Code:
    dim lngLoop as long
    cboJets.clear
    for lngLoop = 0 to ubound(aryData,2)
    
       cboJets.add
       cboJets.list ( lngloop,0)=arydata(lngloop,0)
    next
    with finally (on the combo select or under a button):
    Code:
    msgbox aryData(cboJets.listindex,0) & vbcrlf & aryData(cboJets.listindex,1) & vbcrlf & aryData(cboJets.listindex,2) & vbcrlf & aryData(cboJets.listindex,3) & vbcrlf & aryData(cboJets.listindex,4) & vbcrlf,vbokonly
    If you have the data in a spreadsheet, loop through that to load rathe rthen manually entering. Or use a database table.



    This is only one method of many.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Complicated Combobox

    My suggestion would be to use a database, like Access, to store the information and perform a simply SELECT query based on the combo box selection.

Posting Permissions

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



Click Here to Expand Forum to Full Width