I used a Function: Adding an item to Combobox via code

C

CornDog

This function will load ANY existing report into a
combobox, just set the combobox's rowsource tpye to
ListReports. I'm proud of this one :)

Only Qns I got are:
1) Why cant I have this line
Static ReportNames(100) As String, Entries As Integer

be

Static ReportNames(NumReports) As String, Entries As
Integer

2)This line

Case acLBOpen ' Open.
ReturnVal = Timer

Only lets me use Timer as the Unique ID, why cant I make
it anything I want?

-----------------------The FUNCTION-----------------------
Function ListReports(fld As Control, id As Variant, row As
Variant, col As Variant, code As Variant) As Variant

Dim obj As AccessObject, dbs As Object, NumReports As
Integer, ReportIndex As Integer

Dim ReturnVal As Variant
ReturnVal = Null
Set dbs = Application.CurrentProject

NumReports = 0
For Each obj In dbs.AllReports
NumReports = NumReports + 1
Next obj

Static ReportNames(100) As String, Entries As Integer

Select Case code
Case acLBInitialize ' Initialize.
Entries = 0
''ReportNames(Entries) = Dir("*.*")
ReportNames(Entries) = dbs.AllReports
(Entries).Name

Do Until ReportNames(Entries) = "" Or Entries
= (NumReports - 1)
' Entries = Entries + 1
' ReportNames(Entries) = Dir

' For Each obj In dbs.AllReports
Entries = Entries + 1
ReportNames(Entries) = dbs.AllReports
(Entries).Name
' Next obj 'Loop
Loop
ReturnVal = Entries
Case acLBOpen ' Open.
ReturnVal = Timer ' Unique ID.
Case acLBGetRowCount ' Get rows.'
ReturnVal = Entries 'NumReports
Case acLBGetColumnCount ' Get columns.
ReturnVal = 1
Case acLBGetColumnWidth ' Get column width.
ReturnVal = -1 ' Use default width.
Case acLBGetValue ' Get the data.
ReturnVal = ReportNames(row)
Case acLBEnd ' End.
Erase ReportNames
End Select
ListReports = ReturnVal
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top