Article ID: 124344
Article Last Modified on 1/19/2007
Name: ListBox1
------------------------------------------------------------------
RowSourceType: Value List
RowSource: 1;Tables;2;Queries;3;Forms;4;Reports;5;Macros;6;Modules
ColumnCount: 2
ColumnWidths: 0.25 in;0.75 in
BoundColumn: 2
Name: ListBox2
---------------------------
RowSourceType: FillNameList
Private Sub ListBox1_AfterUpdate()
ListBox2.Requery
End Sub
'**********************************
' Declarations section of the module
'**********************************
Option Compare Database ' Use database order for
' string comparisons.
Option Explicit
Dim list() As String
Dim entries
'**************************************
'Function FillNameList()
'**************************************
Function FillNameList (fld As Control, id, row, col, code)
' Accepts a control, an identifier, a row, a column, and a code.
On Error GoTo ErrorHandler
Dim ReturnVal
Dim x As String
If IsNull(Forms![frmFillListBox]![ListBox1]) Then
x = "Tables"
Else
x = Forms![frmFillListBox]![ListBox1]
End If
ReturnVal = Null
Select Case code
Case 0 ' Initialize.
entries = 0
entries = GetNames(x, list())
ReturnVal = entries
Case 1 ' Open.
ReturnVal = Timer ' Unique ID number for the control.
Case 3 ' Get the number of rows.
ReturnVal = entries
Case 4 ' Get the number of columns.
ReturnVal = 1
Case 5 ' Get the column width.
ReturnVal = -1 ' Use the default width.
Case 6 ' Get the data.
ReturnVal = list(row)
Case 9 ' End.
ReDim list(0)
entries = 0
End Select
FillNameList = ReturnVal
ErrorHandler:
Resume Next
End Function
'*********************
'Function GetNames()
'*********************
Function GetNames (objtype As String, names() As String)
Dim Conta As Container, Db As Database, I, Arlen
Set Db = CurrentDb
' In Microsoft Access 7.0 and earlier, the above line should read:
'
' Set Db = DbEngine.Workspaces(0).Databases(0)
Arlen = 0
If objtype = "Macros" Then
objtype = "Scripts" ' Macros are called scripts, internally.
End If
Select Case objtype
Case "Tables"
If Db.Tabledefs.Count <> 0 Then
Arlen = Db.Tabledefs.Count
ReDim list(0 To Arlen - 1)
I = 0
For I = 0 To (Arlen) - 1
names(i) = Db.Tabledefs(i).Name
Next I
End If
Case "Queries"
If Db.Querydefs.Count <> 0 Then
Arlen = Db.Querydefs.Count
ReDim list(0 To Arlen - 1)
I = 0
For I = 0 To (Arlen) - 1
names(i) = Db.Querydefs(i).Name
Next i
End If
Case Else
Set Conta = Db.Containers(objtype)
If Conta.Documents.Count <> 0 Then
Arlen = Conta.Documents.Count
ReDim list(0 To Conta.Documents.Count - 1)
I = 0
For I = 0 To (Arlen) - 1 ' Fill the Names array
' with object names.
names(i) = Conta.Documents(i).Name
Next I
End If
End Select
Getnames = Arlen ' Return the length of the array to the
' FillNameList() function.
End Function
Additional query words: list function
Keywords: kbhowto kbprogramming kbusage KB124344