Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    59

    Unanswered: Open Form with Specific Data in Listbox

    Hi,
    I am trying to open a form from another form and only specify specific data. However, I am having problems as the data I am looking to be specific in the second form is in a listbox and this seems to be causing troubles.

    In the 1st form I simply have a combo box and command button. When you click the button it opens the 2nd form with the criteria set in the combo box. This is the code for that:

    Code:
        Dim stDocName As String
        Dim stLinkCriteria As String
    
        stDocName = "frm_display_contacts"
        
        stLinkCriteria = "[Interested in:]=" & "'" & Me![Interested_Combo] & "'"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    However, as the data I want to specify is in a listbox in the 2nd form, this currently doesn't work. How can I change the code so it filters the listbox and not the form itself?

    Thanks
    Russ

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    With a command such as

    Forms("FormName")!ListBoxName.RowSource = <SQLStatement>

    or similar
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Nov 2008
    Posts
    59
    Okay,
    So how would I use that? I've tried this:

    Code:
        stDocName = "frm_display_contacts"
        
        stLinkCriteria = "Forms("frm_display_contacts")!QuickSearch.[Interested In:]=" & "'" & Me![Interested_Combo] & "'"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    But this just gives me a debugging error. How would the correct way to phrase it be?

    Cheers
    Russ

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Open the form first, then issue another command to update the listbox.

    DoCmd.OpenForm "frm_display_contacts"

    then

    Forms("frm_display_contacts")![Interested In:].RowSource = <SQLStatement>
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •