Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-06-2009
Member
 
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.
Reply With Quote
  #2  
Old 06-06-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #3  
Old 06-06-2009
Member
 
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.
Reply With Quote
  #4  
Old 06-06-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Combobox Selection To Populate Listbox"
Thread Thread Starter Forum Replies Last Post
Need Help With ComboBox Reyas Software Development 1 29-04-2012 12:53 PM
Auto populate a number of cells from a drop down selection in Excel LuniA MS Office Support 2 21-02-2012 07:48 PM
*HELP* MS Word 07 - Populate a text field based on drop-down list selection klutzington Software Development 1 09-09-2011 03:38 PM
Populate Text Field Based On Drop-Down List Selection Kaalicharan Software Development 6 21-07-2010 09:59 AM
Populate a Drop down list in php from SQL GunFighter Software Development 2 18-03-2009 09:08 AM


All times are GMT +5.5. The time now is 04:10 AM.