Listing the forms in my database

Dirkvwaes

New member
Local time
Today, 08:51
Joined
Dec 2, 2025
Messages
2
Hello everybody!
I have a problem in listing all the forms in my database. Can anybody help me making this?
 
THis site has a pretty good search facilty.
See if you can use the logic here
The O/P there wanted to do more than you do, but you can select the CurrentProject.AllForms

Or here
 
Code:
Public Sub ListAllForms()
    Dim oForms As AccessObject
    With Application.CurrentProject
        For Each oForms In .AllForms
            Debug.Print oForms.Name
        Next
    End With
End Sub
 
Public Sub ListAllForms() Dim oForms As AccessObject With Application.CurrentProject For Each oForms In .AllForms Debug.Print oForms.Name Next End With End Sub
Thanks for the very fast answer. It helped me a lot. Can i do something simular with the reports?
 
I think you can also do this with a query against the MSysObjects table, if you care to avoid using code.

Sent from phone...
 
1764691400969.png

I think you can also do this with a query against the MSysObjects table, if you care to avoid using code.

Sent from phone...
Code:
Private Sub cboObjectType_AfterUpdate()
Dim lngObjectType As Long
Dim strSQL1 As String, strSQL2 As String

strSQL1 = "SELECT MsysObjects.Name FROM MsysObjects WHERE (((Left$([Name], 1)) <> '~') And ((MsysObjects.Type) = "

strSQL2 = " )) ORDER BY MsysObjects.Name"

' Set sql for object name combo
Select Case cboObjectType
    Case "Report"
        lngObjectType = -32764
    Case "Query"
        lngObjectType = 5
    Case "Form"
        lngObjectType = -32768
End Select
Me.cboObjectName.RowSource = strSQL1 & lngObjectType & strSQL2
End Sub
 
Can i do something simular with the reports?

You don't say why you would want to list the reports, but if you want to present users with a list of reports from which they can select one or more to open, then rather than listing the report names, which might be rather cryptic to a user, you can list their plain English Description properties. A report is given a description by right clicking on it in the navigation pane, and selecting Properties from the drop-down menu

The following code for a form's Open event procedure inserts the descriptions in an unbound list box, listing only those reports which have been given a Description property. The Multiselect property of the list box should be set to Simple or Extended as preferred if you want the user to be able to select multiple reports. The list box has two columns, with the report name being inserted into the first and the description into the second. The first column is hidden, so the user sees only the descriptions:

Code:
Private Sub Form_Open(Cancel As Integer)

    Const NODESCRIPTION = 3270
    Dim ctrl As Control
    Dim dbs As DAO.Database
    Dim ctr As DAO.Container
    Dim doc As DAO.Document
    Dim strReportName As String
    Dim strReportDesc As String
   
    Set dbs = CurrentDb
    Set ctr = dbs.Containers("Reports")
    Set ctrl = Me.lstReports
   
    With ctrl
        .RowSourceType = "Value List"
        .RowSource = ""
        .ColumnCount = 2
        .ColumnWidths = 0
    End With
   
    For Each doc In ctr.Documents
        strReportName = doc.Name
        On Error Resume Next
        strReportDesc = doc.Properties("Description")
        If Err.Number = NODESCRIPTION Then
            ' do nothing
         Else
            ctrl.AddItem strReportname & ";" & strReportDesc
        End If
    Next doc
   
End Sub

The code to open the selected report or reports can be put in a button's Click event procedure as follows:

Code:
Private Sub cmdPreview_Click()

     Dim strReport As String
     Dim varItem As Variant
   
     With Me.lstReports
        If .ItemsSelected.Count > 0 Then
            For Each varItem In .ItemsSelected
                strReport = .ItemData(varItem)
                DoCmd.OpenReport strReport, View:=acViewPreview
            Next varItem
        End If
    End With
   
End Sub
 
If you want to list all objects by type, then have a look at my articles with all required code

 
Wow! A question asked and within about four hours there were seven great answers from our pool of volunteer experts. Kudos to this site and all members (those who ask and those who answer).
 

Users who are viewing this thread

Back
Top Bottom