Results 1 to 10 of 10
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Combobox selection populates Listbox

    What do I need? I think you need to code in after update, but what?

    Combox has 4 selections under control named [Section]

    [Section]
    A
    B
    C
    D



    Listbox After Update:

    Like [Forms]![Myform].[Section] & "*" doesn't work


    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    What do you want to do? Do you want the listbox RowSource dependent on selection in combobox, something like:

    SELECT field1 FROM table WHERE field2 = [combobox];

    Then code in the combobox AfterUpdate event or the listbox GotFocus event would be:

    Me.listboxname.Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    June7,
    Corrrect, I want the list box output to be dependent on the combobox selection

    Combobox=[Section]
    Combobox row source = SELECT Distinct Reports.Section FROM Reports ORDER BY Reports.Section;

    Listbox=[Report Name]
    Listbox Row Source = SELECT Reports.[Report Name] FROM Reports WHERE (((Reports.[Section])=[Section]));

    If I put: "Me.[Report Name].Requery" in the Combobox AfterUpdate or Listbox GotFocus, I get a MS Access can't find theObject Me. I tried it in VBA and get Runtime Error 2465.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Recommend no spaces or special characters/punctuation (underscore is exception) in naming convention. Should not use reserved words as names. Reports and Section are both reserved words. https://support.microsoft.com/en-us/kb/286335

    If you do those things, then enclose names in [], although even that will not prevent some issues

    What do you mean by 'in the Combobox AfterUpdate or Listbox GotFocus' - do you mean in the event property? Doesn't go there. Select [Event Procedure] the click the ellipsis (...) to open VBA editor. Type code in procedure.

    Post the complete procedure code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Combobox=[Area]
    Combobox row source = SELECT DISTINCT Document.Area FROM Document WHERE (((Document.Area) Is Not Null)) ORDER BY Document.Area;

    Listbox=[Report Name]
    Listbox Row Source = SELECT Document.[Report_Name] FROM Document WHERE (((Document.Area)=[Area])) ORDER BY Document.[Report_Name];

    Combobox - After Update Event:

    Private Sub Section_AfterUpdate()
    Dim Area, Report_Name As String
    [Me]![Report_Name].[Requery]
    End Sub

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    You declare variables but don't set them with values. Why do you have those variables?

    The combobox is named Section or Area? The code is for a control named Section.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Private Sub Area_AfterUpdate()
    [Me]![Report_Name].[Requery]
    End Sub

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Try:

    Me.[Report_Name].Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Documents.accdb

    This is what I have

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    The controls must be UNBOUND, otherwise you change the data in the record. And since the source of the lists is the only table in the db, you do not want to change the data by selection from these controls.

    There is no reason to have the form RecordSource set.

    The combobox is named Section so either change the combobox name or change Listbox RowSource. Access is being confused by the Area name. Change the combobox name to cbxArea and make other edits as appropriate.

    Also, the listbox is named Reports but the code is for a control named Report_Name.

    Set the appropriate event properties to [Event Procedure].

    Private Sub cbxArea_AfterUpdate()
    Me.Reports.Requery
    End Sub

    Private Sub Reports_GotFocus()
    Me.Reports.Requery
    End Sub
    Last edited by June7; 09-24-2015 at 05:10 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2014, 01:20 PM
  2. Replies: 10
    Last Post: 06-18-2013, 02:00 PM
  3. Replies: 1
    Last Post: 09-10-2012, 11:21 PM
  4. ComboBox populates from seperate Form ComboBox
    By scoobz1234 in forum Forms
    Replies: 1
    Last Post: 04-25-2012, 11:42 AM
  5. Replies: 3
    Last Post: 07-31-2010, 07:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums