ggunter
May 23 2012, 07:54 AM
I have an unbound ListBox control on my form that I want to load in the FormLoad event. My problem is that every way I try to reference the control shows it as null so the "loading" code blows up.
The name of the control is "lstTemplate" and I have tried:
1) Me.lstTemplate
2) [Forms]![frmTemplateList].lstTemplate
3) Dim oList As Object
Set oList = Me.lstTemplate
4) Dim oList As ListBox
Set oList = Me.lstTemplate
5) Dim oList As Control
Set oList = Me.Controls("lstTemplate")
6) Dim oList As Control
Set oList = Me.Controls(Me.lstTemplate)
7) Dim oList As Control
Dim cntl As Control
For Each cntl In Me.Controls
If cntl.Name = "lstTemplate" Then
Set oList = cntl
Exit For
End If
Next
8) Dim oList As Control
Set oList = Me.lstTemplate
What am I missing?? VBA didn't used to be this difficult.
Bob G
May 23 2012, 08:23 AM
are you referring to populating the listbox via vba?
lstTemplate.rowsource = whateveryouneed
accesshawaii
May 23 2012, 08:25 AM
Started posting and see that Bob beat me to the punch. Exactly what Bob said. If it's not in a subform then you just populate the rowsource as in Bob's example.
ScottGem
May 23 2012, 09:43 AM
If you are trying to populate the list, then the Rowsource is the answer. If you are trying to READ the selected value, is the listbox set to allow multiple selections?
ggunter
May 23 2012, 11:32 AM
Thanks Guys!! That did the trick.
Sorry to sound like such a noob. I used to do VBA but I've been tied up with VB DotNet, HTML, and JavaScript for the last seven years. Still trying to get acclimated to the limitations.
accesshawaii
May 23 2012, 12:05 PM
Glad you got it working. Just an FYI, VBA does not have nearly as many limitations as people tend to think.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.