Option Compare Database   'Use database order for string comparisons



Global szObject() As String	'Global array loaded by ObjectList() function.
Global iItemCount As Integer	'Global variable used to index above global array.

'---------------------------------------------------------------------------
'---------------------------------------------------------------------------
Function ListReports (fld As Control, id As Long, row As Long, col As Long, Code As Integer)

'
'This function will interrogate the current MDB using the ObjectList() function and
'fill a list box with existing reports. By using this
'function, the need for a table of reports is eliminated.
'
'By substituting the key word "reports" with (ie. "tables", :forms")
' in the ObjectList() function below,
'a listbox could be filled with ANY type of object list.
'
'Function calls ObjectList() to retrieve data.
'Uses global variables szObject() and iItemCount
'
'6/9/94 Dan Hayman
'
'-----------------------------------------------------------------------------------------------

Select Case Code

    Case 0                                      'Initialize
	ListReports = True
	iResult = ObjectList("Reports")         'Call ObjectList() with document type argument. This will fill global array once to be used later in case statement
    Case 1                                      'Open
	ListReports = Timer                     'Create unique ID for control
    Case 3
	ListReports = UBound(szObject) + 1      'Number of rows / recursion. Uses upper bound of global array set above. Add 1 to compensate for 0 index base. Function will recurs by this value and then exit.
    Case 4
	ListReports = 1                         'Number of columns
    Case 5
	ListReports = .75                       'Column width
    Case 6                                      'Get the data
	ListReports = szObject(iItemCount)      'function name is set to global array variable indexed by another global variable incremented each time the function recurses.
	iItemCount = iItemCount + 1             'Increment global variable to index global array.
	
End Select

If iItemCount = UBound(szObject) + 1 Then iItemCount = 0    'We need to know when to reset global indexing variable. This is done by tracking how many knowing how many times the function recurses. When variable reaches this number we know that this is the last time around and we reset the variable.

End Function

'---------------------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------------------


Function ObjectList (ObjName As String)

'This function interrogates the jet engine and returns a list of
'current objects of the specified type to global array szObject().
'Syntax: ObjectList("Object Name")
'Where Object name = Forms, Reports, Tables, etc.
'A good use for this function would be to fill list boxes with current objects.
'
'6/9/94 Dan Hayman
'
'--------------------------------------------------------------------------------------

Dim DefaultWorkspace As WorkSpace
Dim CurrentDatabase As Database
Dim MyContainer As Container, Mydocument As Document
Dim I As Integer, j As Integer

    Set DefaultWorkspace = DBEngine.Workspaces(0)		'Dim DAO workspace, etc.
    Set CurrentDatabase = DefaultWorkspace.Databases(0)

    For j = 0 To CurrentDatabase.Containers.Count - 1		'Loop through all containers
	Set MyContainer = CurrentDatabase.Containers(j)
	If MyContainer.Name = ObjName Then			'If the current container is the desired container, loop through it's contents
	   ReDim szObject(MyContainer.Documents.Count - 1)	'ReDim global variable with current number of documents on desired container
	   For I = 0 To MyContainer.Documents.Count - 1		'Loop through all documents in desired container
		Set Mydocument = MyContainer.Documents(I)	
		Debug.Print Mydocument.Name			
		szObject(I) = Mydocument.Name			'Load global array with document names
	   Next I
	End If
    Next j

End Function

