Consulting

Results 1 to 11 of 11

Thread: Solved: Listbox - Double Click to add data into userform field

  1. #1
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location

    Solved: Listbox - Double Click to add data into userform field

    Hi There,

    If the user double clicks an item in the listbox list i want this to be placed into a seperate field on a nother userform. How can I go about doing this?

    The forms used are :-

    frmDSTCallLog
    frmStaffList

    frmStaffList is called from within frmDSTCallLog when the user clicks the 'StaffList' command button, although ideally it would also launch when the user double clicks into the field txtOne.

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    So you want to open staff list and double click a name and have it go into what field? Original processed by?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Well, since you didn't provide a password and your file is read only, I had to recreate the entire scenario the best I could......

    [VBA]Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    frmDSTCallLog.txtOne.Value = Me.ListBox1.ListIndex + 1
    Unload Me
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Yeah, that would be an accurate assumption.
    I'm looking at changing the way the email section of the main form (frmDSTCallLog) works.
    Instead of the user choosing a subject line, The user would choose the "original processed by" and this will then fill in the "email subject". However, i've no idea how to make VBA do a vlookup.

    So,

    User enters orginal processed by,
    VBA does a vlookup for the name on 'StaffListLookup' (two columns, 'Name | Location'),
    Location is then placed into a field txtLocation.

    Your thoughts?

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  5. #5
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Quote Originally Posted by lucas
    Well, since you didn't provide a password and your file is read only, I had to recreate the entire scenario the best I could......

    [vba]Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    frmDSTCallLog.txtOne.Value = Me.ListBox1.ListIndex + 1
    Unload Me
    End Sub
    [/vba]
    I thought i'd stripped the password! Sorry!
    Password is 0range (with a zero).
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  6. #6
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    The code does work, however instead of entering the value it enters a number. The listbox(s) is populated by the following :
    [vba]cboTempList.List = WorksheetFunction.Transpose(ws.Range("HalifaxTemps"))
    cboHalifaxCM.List = WorksheetFunction.Transpose(ws.Range("HalifaxCM"))
    cboSundCM.List = WorksheetFunction.Transpose(ws.Range("SunderlandCM"))[/vba]
    How can I get the text value and not a numerical entry?

    Cheers,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Well Dave, the password you provide does not allow me access to the file and the one I created used numbers to populate the listbox which has nothing to do with your workbook except that it demonstrates how to double click a listbox and have the selected item be placed in a different userform and textbox.......

    If you add my code to your userform frmstafflist what happens?

    You can either provide a password that works or remove the protection and re-upload the workbook......otherwise, I can't help much.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Steve, my apologies. it would appear I didn't remove the 'read-only' password which is p1neapple. Assuming that I also failed to remove the other passwords they are : k1wifruit (worksheet) and as previously noted 0range (code).
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  9. #9
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Steve, I added the code that you provided into my worksheet without looking at your attachment. So the comment I nade regarding it producing a number is correct from what I can see.

    thanks for your help so far.
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Ok Dave, that helps a lot. Try it now and see if we are getting close. By the way, I strongly advise that you add Option explicit to the very top line of every module, userform, sheet, thisworkbook, etc.

    By the way, you were right about the number after I was able to look at it....index was incorrect, I changed it and added this code to your frmstafflist

    [VBA]Private Sub lbxHalifax_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    frmDSTCallLog.txtOne.Value = Me.lbxHalifax.Value
    Unload Me
    End Sub

    Private Sub lbxHalifaxTemps_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    frmDSTCallLog.txtOne.Value = Me.lbxHalifaxTemps.Value
    Unload Me
    End Sub

    Private Sub lbxSunderland_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    frmDSTCallLog.txtOne.Value = Me.lbxSunderland.Value
    Unload Me
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Steve,

    Many thanks for the assistance wth this one the above code works nicely.

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

Posting Permissions

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