UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Populate Combo Box With Form Names, Access 2016    
 
   
TimTDP
post Sep 14 2016, 07:34 AM
Post#1



Posts: 1,117
Joined: 16-June 05



How can I populate a combo box with a list of all forms in the database?

Thanks in advance
Go to the top of the page
 
dashiellx2000
post Sep 14 2016, 07:56 AM
Post#2


UtterAccess VIP
Posts: 9,864
Joined: 11-March 05
From: Maryland


You would need to return the names of the forms as a string and then set that as the Combo Box's RowSource.
Go to the top of the page
 
GroverParkGeorge
post Sep 14 2016, 07:57 AM
Post#3


UA Admin
Posts: 37,521
Joined: 20-June 02
From: Newcastle, WA


Do you want the actual form names, or a "friendly" name? e.g. frmManageVendors, or Manage Vendors.

This query will give you the form names used by Access.

SELECT MSysObjects.Name
FROM MSysObjects
WHERE MSysObjects.Type=-32768;

However, I would probably create a table with columns for the actual form name and a friendly version of it to show to users. You can populate it by converting that SQL to an APPEND.
Go to the top of the page
 
RAZMaddaz
post Sep 14 2016, 08:08 AM
Post#4


UtterAccess VIP
Posts: 9,601
Joined: 23-May 05
From: Bethesda, MD USA


Here is another example.

You will need to have a list box named "ListObjects." And as you will see in the code it returns all the Tables, Forms, Queries, etc. that are in your Table. Simple remove from the code the Tables, Forms or whatever you don't want to show in the list.

CODE
Private Sub Form_Load()
Dim accObject As Access.AccessObject
    
    'Fill with Tables
    For Each accObject In CurrentData.AllTables
        Me.ListObjects.AddItem "TABLE;" & accObject.Name
    Next
        
    'If currently opened file is an Access database (mdb), then fill
    'with queries.
    'Otherwise, if it is an Access project (adp), fill with views,
    'stored procedures, database diagrams, and functions.
    If CurrentProject.ProjectType = acMDB Then
        For Each accObject In CurrentData.AllQueries
            Me.ListObjects.AddItem "QUERY;" & accObject.Name
        Next
    Else
        For Each accObject In CurrentData.AllViews
            Me.ListObjects.AddItem "VIEW;" & accObject.Name
        Next
        For Each accObject In CurrentData.AllStoredProcedures
            Me.ListObjects.AddItem "PROCEDURE;" & accObject.Name
        Next
        For Each accObject In CurrentData.AllDatabaseDiagrams
            Me.ListObjects.AddItem "DIAGRAM;" & accObject.Name
        Next
        For Each accObject In CurrentData.AllFunctions
            Me.ListObjects.AddItem "FUNCTION;" & accObject.Name
        Next
    End If
    
    'Fill list with forms.
    For Each accObject In CurrentProject.AllForms
        Me.ListObjects.AddItem "FORM;" & accObject.Name
    Next
    'Fill list with reports.
    For Each accObject In CurrentProject.AllReports
        Me.ListObjects.AddItem "REPORT;" & accObject.Name
    Next
    'Fill list with data access pages.
    For Each accObject In CurrentProject.AllDataAccessPages
        Me.ListObjects.AddItem "PAGE;" & accObject.Name
    Next
    'Fill list with macros.
    For Each accObject In CurrentProject.AllMacros
        Me.ListObjects.AddItem "MACRO;" & accObject.Name
    Next
    'Fill list with modules.
    For Each accObject In CurrentProject.AllModules
        Me.ListObjects.AddItem "MODULE;" & accObject.Name
    Next

End Sub



RAZMaddaz
Go to the top of the page
 
GroverParkGeorge
post Sep 14 2016, 09:25 AM
Post#5


UA Admin
Posts: 37,521
Joined: 20-June 02
From: Newcastle, WA


It looks like you have at least three alternative ways to get the job done.

Pick the one most comfortable to you.

Best of luck with your project.
Go to the top of the page
 
ADezii
post Sep 14 2016, 10:56 AM
Post#6



Posts: 3,090
Joined: 4-February 07
From: USA, Florida, Delray Beach


One critical point not mentioned is that if you are adding Form Names to a Combo Box as you previously indicated, you must set the RowSourceType of the Combo Box to 'Value List'. Assuming your Combo Box is named cboForms:
CODE
Dim obj As AccessObject
Dim oProject As Object
Dim cbo As Access.ComboBox

Set oProject = Application.CurrentProject
Set cbo = Me![cboForms]

cbo.RowSourceType = "Value List"        'critical setting
    
For Each obj In oProject.AllForms
  cbo.AddItem obj.Name
Next obj
Go to the top of the page
 
MrFormula
post Apr 10 2020, 06:24 PM
Post#7



Posts: 744
Joined: 28-May 05



Thanks for posting this.
I did a quick search and found this information
I used
CODE
SELECT MSysObjects.Name
FROM MSysObjects
WHERE MSysObjects.Type=-32768;


Worked Perfect. Just wanted to say thanks
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    16th July 2020 - 08:33 AM