Results 1 to 5 of 5

User Form won't Initialize. Run time error

This is a discussion on User Form won't Initialize. Run time error within the Excel Questions forums, part of the Question Forums category; Hello everyone: I am having an issue with my form initializing. The form name is frmAddRepresentative and has a combo ...

  1. #1
    Board Regular
    Join Date
    Mar 2011
    Posts
    678

    Default User Form won't Initialize. Run time error

    Hello everyone:

    I am having an issue with my form initializing. The form name is frmAddRepresentative and has a combo box called cboRepName. The code below should run when the form initializes. But I am getting a run time error -2147467259 (80004005). Unespecified error. Not much help from that.

    Also, I change UserForm_Initialize to frmAddRepresentative_Initialize, the form opens but I get a subscript out of range on the Me.cboRepName references.

    I can't figure out what I am doing wrong.

    Code:
    Option Explicit
    
    Private Sub UserForm_Initialize()
    Dim ws As Worksheet
    Set ws = Worksheets("Rep Information")
     
    UpdateComboLists
     
    Me.cboRepName.SetFocus
     
    End Sub
     
    Private Sub UpdateComboLists()
    
    Dim cName As Range
    Dim ws As Worksheet
    Set ws = Worksheets("Rep Information")
     
    Me.cboRepName.Clear
    For Each cName In ws.Range("repName")
      
      With Me.cboRepName
      
        .AddItem cName.Value
        .List(.ListCount - 1, 1) = cName.Offset(0, 1).Value
      
      End With
    Next cName
     
    End Sub

  2. #2
    Board Regular
    Join Date
    Jul 2006
    Location
    Brussels
    Posts
    7,589

    Default Re: User Form won't Initialize. Run time error

    Quote Originally Posted by jmazorra View Post
    Also, I change UserForm_Initialize to frmAddRepresentative_Initialize
    Please do not do this. Just use UserForm_Initialize and in the code module for the Userform.

    Execute the macro that loads the userform by pressing F8 on that macro (repeatedly, line by line).
    That way, you can debug the Initialize event.
    Regards,


    Wigi


    Excel MVP 2011, 2012, 2013



    For more Excel memes: visit http://www.wimgielis.be ==> English articles ==> Excel memes

    -- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --

  3. #3
    Board Regular
    Join Date
    Mar 2011
    Posts
    678

    Default Re: User Form won't Initialize. Run time error

    Thank you, I did as you said and the error seems to be in the For Loop,

    For Each cName In ws.Range("repName")

    But I can't figure out why there would be an error. I named the variable rngName and I am using a named range repName. This should be working.

  4. #4
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling
    Posts
    65,841

    Default Re: User Form won't Initialize. Run time error

    Are there any values in repName?

    Have you previously used RowSource to populate the listbox?
    If posting code please use code tags.

  5. #5
    Board Regular
    Join Date
    Mar 2011
    Posts
    678

    Default Re: User Form won't Initialize. Run time error

    Thanks, just for kicks I changed the name of my named range from repName to Names and it works fine now. There must be something with the naming convention.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com