+ Reply to Thread
Results 1 to 7 of 7

List boxes not displaying choices

Hybrid View

WillysK5 List boxes not displaying... 02-19-2009, 12:16 PM
royUK Re: List boxes not displaying... 02-19-2009, 12:20 PM
Andy Pope Re: List boxes not displaying... 02-19-2009, 12:44 PM
WillysK5 Re: List boxes not displaying... 02-19-2009, 02:00 PM
WillysK5 Re: List boxes not displaying... 03-10-2009, 12:46 PM
Andy Pope Re: List boxes not displaying... 03-10-2009, 12:54 PM
WillysK5 Re: List boxes not displaying... 03-10-2009, 01:07 PM
  1. #1
    Registered User
    Join Date
    05-20-2008
    MS-Off Ver
    2003 suite
    Posts
    64

    List boxes not displaying choices

    Hello all. I'm very new to the VB experience and am having trouble getting the choices in my list boxes to show up.

    Here's my code.

    Private Sub UserForm1_Initialize()
        txtJobNumber.Value = ""
        txtCustomer.Value = ""
        txtProject.Value = ""
        txtDeliverTo.Value = ""
        txtWantedby.Value = ""
        txtSchedbuildon.Value = ""
        txtScheduledon.Value = ""
        txtEsthrs.Value = ""
        cboStatus.Value = ""
        With cboSalesman
            .AddItem "SL"
            .AddItem "MG"
            .AddItem "WC"
        End With
        cboSalesman.Value = ""
        With cboDesigner
            .AddItem "MS"
            .AddItem "BA"
            .AddItem "JM"
            .AddItem "DH"
            .AddItem "DR"
            .AddItem "DC"
        End With
        cboDesigner.Value = ""
        With cboStatus
            .AddItem "Des"
            .AddItem "TRP"
        End With
        cboStatus.Value = ""
        With cboJobtype
            .AddItem "Res"
            .AddItem "Com"
            .AddItem "PB"
            .AddItem "Add"
        End With
        cboJobtype.Value = ""
        txtJobNumber.SetFocus
    End Sub
    Am I missing something?

    Thanks!
    Last edited by NBVC; 03-10-2009 at 01:21 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: List boxes not displaying choices

    Try this
    Option Explicit
    Private Sub UserForm1_Initialize()
        txtJobNumber.ListIndex = 0
        txtCustomer.Value = ""
        txtProject.Value = ""
        txtDeliverTo.Value = ""
        txtWantedby.Value = ""
        txtSchedbuildon.Value = ""
        txtScheduledon.Value = ""
        txtEsthrs.Value = ""
        cboStatus.ListIndex = 0
        With cboSalesman
            .AddItem "SL"
            .AddItem "MG"
            .AddItem "WC"
        End With
        cboSalesman.ListIndex = 0
        With cboDesigner
            .AddItem "MS"
            .AddItem "BA"
            .AddItem "JM"
            .AddItem "DH"
            .AddItem "DR"
            .AddItem "DC"
        End With
        cboDesigner.ListIndex = 0
        With cboStatus
            .AddItem "Des"
            .AddItem "TRP"
        End With
        cboStatus.ListIndex = 0
        With cboJobtype
            .AddItem "Res"
            .AddItem "Com"
            .AddItem "PB"
            .AddItem "Add"
        End With
        cboJobtype.ListIndex = 0
        txtJobNumber.SetFocus
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: List boxes not displaying choices

    Your code should be in the Initialize event of the userform.

    Your routine name means that is treated as a private sub in the userform object. Userform1_Initialize is not an event.

    Private Sub UserForm_Initialize()
    
    End Sub
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    05-20-2008
    MS-Off Ver
    2003 suite
    Posts
    64

    Re: List boxes not displaying choices

    That was it! It's always the little stuff...

    Thanks Andy!

    Quote Originally Posted by Andy Pope View Post
    Your code should be in the Initialize event of the userform.

    Your routine name means that is treated as a private sub in the userform object. Userform1_Initialize is not an event.

    Private Sub UserForm_Initialize()
    
    End Sub

  5. #5
    Registered User
    Join Date
    05-20-2008
    MS-Off Ver
    2003 suite
    Posts
    64

    Re: List boxes not displaying choices

    Well, I'm working on a different project and am having the same problem.

    The Initialize starts out like this:

    Private Sub UserForm_Initialize()
        txtJobNumber.Value = ""
        txtCustomer.Value = ""
        txtProject.Value = ""
        txtDeliverTo.Value = ""
    But I get an error pointing to this Module. It highlights UserForm1.show

    Sub OpenUserForm1()
        UserForm1.Show
    End Sub
    The name of the form is UserForm1.

    It works in the other project!!

    Does it matter what order the Subs are in? Cause that's the only difference I can find.

    Thanks!

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: List boxes not displaying choices

    You need to step through the code line by line as the error is occuring within the userform load/initialize process.

  7. #7
    Registered User
    Join Date
    05-20-2008
    MS-Off Ver
    2003 suite
    Posts
    64

    Re: List boxes not displaying choices

    Thanks for teaching a noob Andy. Got it to work. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1