Results 1 to 3 of 3

Thread: [RESOLVED] Create combobox object in code

  1. #1

    Thread Starter
    Member sgarv's Avatar
    Join Date
    Jul 2012
    Posts
    34

    Resolved [RESOLVED] Create combobox object in code

    I am using VB6, SP5.

    I need to call a routine that takes a combobox as a parameter. I am doing something like this:

    Dim cboTest as ComboBox

    sLoadItems cboTest

    if cboTest.ListCount >0 then
    msgbox cboTest.ListCount & " items were loaded"
    else
    msgbox "No items were loaded"

    end if

    Seems simple enough; however, it produces error 91, Object not set. I tried changing the declaration to the following:

    Dim cboTest as New ComboBox

    Now it gives me the error that I am using the New keyword incorrectly.

    Set cboTest = new ComboBox

    This produces the same results. What am I missing?

    I do not want to add the combo box to the GUI; I do not have one since my code resides in a module. Thank you, Saga

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Create combobox object in code

    You have declared the object but not created it. You can create the combo using the controls collection.
    Code:
    Dim cboTest As ComboBox
    
        Set cboTest = Controls.Add("VB.Combobox", "cboTest")

  3. #3

    Thread Starter
    Member sgarv's Avatar
    Join Date
    Jul 2012
    Posts
    34

    Re: Create combobox object in code

    Huh, for some reason my post did not appear. Anyways...

    That got it to work! Thanks! Incredible the stuff that I forget when I don't use it. Saga

Tags for this Thread

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