Results 1 to 4 of 4

Thread: Combobox Selection To Populate Listbox

  1. #1
    Join Date
    Jan 2009
    Posts
    58

    Combobox Selection To Populate Listbox

    I want to have a code in VBA where i can populate a list box based on the value of a combo box because i need to give the my user ability to select from list box i have also try to ask my friends and try to find it over internet but was not able to get it so i have posted here hope my query gets solved.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Combobox Selection To Populate Listbox

    Try to follow the below steps:-

    1. Open the sample database Northwind.
    2. In the Database Window, click Forms, and then click New.
    3. In the New Form dialog box, click Design View, and then click OK.
    4. Add a combo box control on the form.
    5. Right-click the combo box, click Properties, and then set the following properties for the combo box

      Code:
      Name: cmbReports
      RowSourceType: Table/Query
      LimitToList: Yes
      Left: 2"
      Top: 0.5"
      Width: 2"
    6. Now assign the following SQL statement to the RowSource property:
    7. Code:
      SELECT Name, Type FROM MSysObjects WHERE Type=-32764 ORDER BY Name;
    8. Now right-click on label, click Properties, and then set the following properties for the label:

      Code:
      Name: lblReports
      Caption: Reports:
      Left: 1"
      Top: 0.5"
      Width: 1"
      FontWeight: Bold
      TextAlign: Right
    9. On the File menu, click Save, type frmListReports in the Form Name box, and then click OK.
    10. On the View menu, click Form View. Note that the reports are listed in alphabetical order.

  3. #3
    Join Date
    Jan 2009
    Posts
    58

    Re: Combobox Selection To Populate Listbox

    I have try to do the following things but still facing same issue. Is there any other method then please post me.

  4. #4
    Join Date
    Dec 2008
    Posts
    137

    Re: Combobox Selection To Populate Listbox

    Try to follow this steps i am sure this will work for you.

    • Open the sample database Northwind.
    • In the Database window, click Forms, and then click New.
    • In the New Form dialog box, click Design View, and then click OK.
    • Add a combo box control to the form.
    • Right-click the combo box, click Properties, and then set the following properties for the combo box:

      Code:
               Name: cmbReports
               RowSourceType: fncGetReports
               LimitToList: Yes
               Left: 2"
               Top: 0.5"
               Width: 2"
    • Right-click the label, click Properties, and then set the following properties for the label:

      Code:
               Name: lblReports
               Caption: Reports:
               Left: 1"
               Top: 0.5"
               Width: 1"
               FontWeight: Bold
               TextAlign: Right
    • On the View menu, click Code, and then copy or paste the following code:

      Code:
            Function fncGetReports(Ctrl As Control, varID As Variant, _
                     varRow As Variant, varCol As Variant, varCode As Variant) _
                     As Variant
      
               'Assign all report names to the combo box.
                Dim obj As AccessObject
                Dim proj As CurrentProject
      
                Set proj = Application.CurrentProject
      
                Select Case varCode
                    Case acLBInitialize
                        fncGetReports = True
                    Case acLBOpen
                        fncGetReports = Timer
                    Case acLBGetRowCount
                        fncGetReports = proj.AllReports.Count
                    Case acLBGetColumnCount
                        fncGetReports = 1
                    Case acLBGetColumnWidth
                        fncGetReports = -1
                  Case acLBGetValue
                      Set obj = proj.AllReports(varRow)
                      fncGetReports = obj.Name
               End Select
            End Function
    • On the File menu, click Close and Return to Microsoft Access.
    • On the File menu, click Save, type frmListReports in the Form Name box, and then click OK.
    • On the View menu, click Form View. Note that the reports are not listed in alphabetical order. For example, the Employee Sales by Country report appears second from the bottom instead of immediately following the Customer Labels report.

Similar Threads

  1. Need Help With ComboBox
    By Reyas in forum Software Development
    Replies: 1
    Last Post: 29-04-2012, 12:53 PM
  2. Replies: 2
    Last Post: 21-02-2012, 07:48 PM
  3. Replies: 1
    Last Post: 09-09-2011, 03:38 PM
  4. Populate Text Field Based On Drop-Down List Selection
    By Kaalicharan in forum Software Development
    Replies: 6
    Last Post: 21-07-2010, 09:59 AM
  5. Populate a Drop down list in php from SQL
    By GunFighter in forum Software Development
    Replies: 2
    Last Post: 18-03-2009, 09:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,973,783.35621 seconds with 16 queries