Populate listbox from array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi -

I need to populate a listbox from values in an array, but I'm having a hard
time. I have a front/back end structure set up and there is a table in the
backend that I DON't want to link into the front end. I want to get values
from that backend table, store the values in an array, then use the values in
that array to populate a list box on a form. The # of rows in the array will
vary.

Can I do this and if so, can someone help??

Thanks,
J
 
Hi Doug -

That's actually the examples that I was working off of. Here's my code
below. This works, but I want the MyDeptArray to vary. For example, if user
X opens the database, it gets their depts and populates the array (may be 2
depts). If user Y opens the database, it gets their depts and populates the
array (may be 4 depts). I'm not sure when to populate the array and how to
use it in the below example. I'm also not sure what Static dbs(127) as
string is doing.

Any help is appreciated. Thanks.

Function ListDept(fld As Control, id As Variant, _
row As Variant, col As Variant, _
code As Variant) As Variant
Static dbs(127) As String, Entries As Integer
Dim ReturnVal As Variant
ReturnVal = Null

MyDeptArray = Array("01", "02")

Select Case code
Case acLBInitialize ' Initialize.
Entries = 2
ReturnVal = Entries
Case acLBOpen ' Open.
' Generate unique ID for control.
ReturnVal = Timer
Case acLBGetRowCount ' Get number of rows.
ReturnVal = Entries
Case acLBGetColumnCount ' Get number of columns.
ReturnVal = 1
Case acLBGetColumnWidth ' Column width.
' -1 forces use of default width.
ReturnVal = -1
Case acLBGetValue ' Get data.
ReturnVal = MyDeptArray(row)
Case acLBEnd ' End.
Erase dbs
End Select
ListDept = ReturnVal
End Function
 
Static dbs(127) As String isn't required in your case: in the example cited,
it's where the file names are being stored. You'll want to replace it with
your MyDeptArray:

Static MyDeptArray As Variant

What you need to do is initialize MyDeptArray in the acLBInitialize case:

Case acLBInitialize
If User = X Then
MyDeptArray = Array("01", "02")
Entries = 2
ReturnVal = Entries
ElseIf User = Y Then
MyDeptArray = Array("01", "03", "04", "05")
Entries = 4
ReturnVal = Entries
Else
Entries = 0
ReturnVal = Entries
End If User
 
Back
Top