maxy88
asked on
Pass Listbox by reference
Hello,
I have a list box called "lst_AddIPP_AvailableParts
Private Sub lst_AddIPP_AvailableParts_
EvaluateListClick lst_AddIPP_AvailableParts,
End Sub
The function that evaluates the listbox, "EvaluateListClick" is defined below:
Private Sub EvaluateListClick(ByRef mylist As Access.listbox, ByRef mybtn As Button)
Dim bck As Boolean
Dim varItm As Variant
bck = False
For Each varItm In mylist.ItemsSelected
bck = True
Exit For
Next varItm
If bck = True Then
mybtn.Enabled = True
Else
mybtn.Enabled = False
End If
End Sub
The form crashes when the user clicks the listbox and the error message says: "Type mismatch". The debugger says the listbox passed to "EvaluateListClick" has a value of null. Interestingly if I use the listbox on the line above the "EvaluateListClick" call, it works fine. Also fine works when I pass the listbox as a parameter to a subroutine when a button is clicked. The only place I get this error is when I try to pass the listbox as a parameter from within the listbox event.
Not sure how to get rid of this problem. Can someone help?
To replicate, place a listbox on a form and add an onClick event. Use the above code for the implementation.
The listbox has the multiselect property set to True.
Cheers,
Max.
what line does the type mismatch occur on?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well done, MageDribble how did you know that was the culprit?
Max.
Access doesn't have Buttons. VB.NET does but Access does not. Access only has CommandButtons and if you are in the Access environment you shouldn't need to prefix with Access.ListBox
I know that was the culprit because I've done it before :)
Good luck with your project!
I know that was the culprit because I've done it before :)
Good luck with your project!