User form issue

I am trying to launch a user form from a word document using a command button, but I am getting the following error "Sub or Function not defined."

The code for the user form is listed below:

Private Sub frmSegment_Initialize()
With ListBox1
.AddItem "RNA"
.AddItem "ISMC"
.AddItem "MHS"
End With
End Sub

Now like I stated earlier I want to be able to launch this userform when a user selects the "launch" command button. And to do that I entered this code for the command button:

Private Sub cmdLaunch_Click()
frmSegment_Initialize
frmSegment.Show
End Sub

However I am getting that error message. This code happens to be in the "ThisDocument" section while the userfrom code is under the forms folder of the project. How can I make the launch button initialize the userform and show it


Answer this question

User form issue

  • Greenmtnsun

    I'd move your code into a Form_Initialize event handler, and then load the form this way:

    Load Form1
    Form1.Show

    Does this do it



  • ananta

    I removed the frmSegment_Initialize but now when the userform launches, the items in the first list are not populated. frmSegment.Show is not calling the initialize sub. Any ideas

  • ravi.velu

    You have renamed the Initialize event procedure. Change it back to this:

    Private Sub UserForm_Initialize()
      With Me.ListBox1
        .AddItem "RNA"
        .AddItem "ISMC"
        .AddItem "MHS"
      End With
    End Sub

    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Tutorials and Custom Solutions
    http://PeltierTech.com
    _______



  • BhuttCrackSpackle

    Hello,

    In your sub cmdLaunch_Click, take ou the line that reads frmSegment_Initialize.

    the line frmSegment.Show will call the initialize sub anyway.

    Chas


  • User form issue