Results 1 to 5 of 5

Thread: Populate combobox with data in a text file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    n/a
    Posts
    89

    Populate combobox with data in a text file

    I have a text file with a list of names that I want to populate into a combo box. Below is the code I am trying. It works for a text box, but I get errors when I try it with a combo box. Am I taking the correct approach?


    Code:
    Private Sub Form_Load() 
    
    'Outline:       - Asks the user for a file.
        '              - Reads all the data into Text1.
        
        Dim FilePath As String
        Dim Data As String
        
        FilePath = InputBox("Enter the path for a text file", "The Two R's", _
        "C:\users.TXT")
        'Asks the user for some input via an input box.
        
        Open FilePath For Input As #1
        'Opens the file given by the user.
        
        Do Until EOF(1)
        'Does this loop until End Of File(EOF) for file number 1.
            Line Input #1, Data
            'Read one line and puts it into the varible Data.
            Combo11.Text = Combo11.Text & vbCrLf & Data
            'Adds the read line into Text1.
            MsgBox EOF(1)
        Loop
        
        Close #1
        'Closes this file.
    n/a

  2. #2
    Lively Member
    Join Date
    May 2001
    Location
    Leicester, UK
    Posts
    92
    you need to use
    combo1.additem not combo1.text to add to a combo box.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    n/a
    Posts
    89
    using additem requires you to specify what is in your combobox in the code. I want to specify a path in which to import a list.

    I don't know of a way to use additem to do this.
    n/a

  4. #4
    rsitogp
    Guest
    Why, you can do the following with combobox
    Code:
    Open "anyfile.txt" for input as #1
    Do Until EOF(1)
     Input #1, data2add
     Combo1.Additem data2add
    Loop
    Close #1
    Works GREAT!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    n/a
    Posts
    89
    Thanks, you are the best!!
    n/a

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