Results 1 to 4 of 4

Thread: UserForm interaction and Doubleclick events

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    14

    UserForm interaction and Doubleclick events

    Hello,

    I'm making a macro for printing with tray selections. The macro that I'm making is this far: all the sheetnames of the excel document get inserted into a ListBox. And then comes the following step:

    When you doubleclick on the sheetname in the list, a new UserForm will open (that contains the sheetname and a combolist that contains 7 options of printers).

    So question 1 is: how do you write an event that opens UserForm2 by clicking on an item in a listbox? (simple code please)

    The next thing: I want the label in UserForm2 to contain the name of the doubleclicked item in the ListBox. I tried this:

    Label1.Caption = CStr(ListBox1.List(i - 1))

    It however doesn't work.

    So question 2: How do I get the name of a ListItem from one userform to a label in another userform? (simple code please)

    And my last question is: When I have a variable in a userform. How do I recall the variable from another userform? (Also simple code please)

    I'm really hoping you could help me. I'm really stuck now...

    Jeroen

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: UserForm interaction and Doubleclick events

    put in the click event for the listbox
    userform2.show

    normally you would use the click event of the list box, but in this case
    put in the dblclick event
    label1 = listbox1.text
    or
    userform3.label7 = listbox1.text

    myvar = userform2.somevar
    where somevar is defined in the general section at the top of userform2 as public
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    14

    Re: UserForm interaction and Doubleclick events

    Thank you.

    However , I tried the following event

    Private Sub listbox1_dblclick()


    End Sub

    and also this one:

    Private Sub listbox1_doubleclick()


    End Sub

    they both don't work.. How do I make the doubleclick event?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: UserForm interaction and Doubleclick events

    you do not make it, select from the dropdown boxes at top of code pane of userform that contains listbox
    listbox in left then event in right

    vb Code:
    1. Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    2. Label1 = ListBox1.Text
    3.  
    4. End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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