Is there any way you can upload a sample of your data? Would be super helpful to save us the time of trying to re-create what you have.
If you double click the Reply to Thread button, you can upload a sample workbook there.
Hello,
I have been using this training piece of vb code for a database, everything else is working OK but I can not get the event on the double click on my list box value to pick up the selected line and set it to TRUE.
If lstlookup.selected(I) = TRUE
I would be grateful if someone could let me know what I have done wrong. this is the code I am using.
Thank you in advance for your help.
Code:Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 'declare the variables Dim ID As String Dim I As Integer Dim findvalue 'error block On Error GoTo errHandler: 'get the select value from the listbox For I = 0 To LstLookup.ListCount - 1 If LstLookup.Selected(I) = True Then 'set the listbox column ID = LstLookup.List(I, 9) End If Next I 'find the value in the range Set findvalue = Sheet2.Range("L:L").Find(What:=ID, LookIn:=xlValues).Offset(0, -9) 'add the values to the userform controls cNum = 10 For X = 1 To cNum Me.Controls("Reg" & X).Value = findvalue Set findvalue = findvalue.Offset(0, 1) Next 'disable the controls to make the user select an option 'error block On Error GoTo 0 Exit Sub errHandler:: MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " _ & Err.Number & vbCrLf & Err.Description & vbCrLf & _ "Please notify the administrator" End Sub
Last edited by Bob Phillips; 2015-03-14 at 09:33 PM. Reason: Added code tags
Is there any way you can upload a sample of your data? Would be super helpful to save us the time of trying to re-create what you have.
If you double click the Reply to Thread button, you can upload a sample workbook there.
Ken Puls, FCPA, FCMA, MS MVP
Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!
Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter
If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.
Hi Ken,
Thank you for the reply,this is a sample of the test data I am using.
I have tried putting Msgbox around the '.Selected(I) statement but it is always FASLE
For I = 0 To lstLookup.ListCount- 1
If lstLookup.Selected(I) = True Then
'set the listbox column
ID = lstLookup.List(I, 9)
End If
Next I
Data ----------------
First Name Last Name Grade StaffID Department Training Completed Frequency Due ID Joe Jones 3 DeCl28 Administration Cydotoxic 19/06/2014 547 18/12/2015 101 Arthur Jolley 3 DeCl28 Administration Fire Training 10/12/2013 30 01/09/2014 144 fred Smith 3 DeCl28 Administration Patient Handling 12/12/2013 120 11/04/2014 154
Regards John.
Bookmarks