Results 1 to 12 of 12
  1. #1
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76

    option group pass different value to same listbox

    Hi all,



    I have a option group with 4 toggle buttons, and a list box below my option group. I want to pass the different fields from the same query to the list box depending on which button I clicked, Can anyone give me some ideas on how to achieve that?

    Thanks!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    There is a youtube video here that has some info. I think you could get ideas from it and adapt to your needs.
    http://www.youtube.com/watch?v=h5M-QJnc2u0

  3. #3
    t. hagan is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    7
    Quote Originally Posted by ice051505 View Post
    Hi all,

    I have a option group with 4 toggle buttons, and a list box below my option group. I want to pass the different fields from the same query to the list box depending on which button I clicked, Can anyone give me some ideas on how to achieve that?

    Thanks!
    You could create a query that filters records based on the selections that you made in your option group. Let’s call it “Filter Query.”
    The option group will have to match one of the fields in your list box. The Filter Query would set the following criteria for the column in your list that matches with the selection in the option group: [Forms]![Name of your form]![Name of option group].
    Filter Query would be used as the data source for the listbox. You would refresh the form and/or the listbox every time the value in the option group was changed. (me.requery, me.refresh, listbox.refresh, I am mentioning all because I can't remember offhand which is needed and I have often ended using all of the above when using this technique).
    This is a pretty common technique known as filtering by form. It is described in all of the Access manuals that I have read. If you query for "filter by form" I this site, I am confident that you will get some hits. You might also want to try "filter by combobox."
    t. hagan
    www.peachtek.net

  4. #4
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Thanks t.hagan, but actually my problem is to select the optional group first, then the selection will shows in the listbox, which means my option group has 4 button: A, B, C and D. I have a source query with 5 fields: ID A B C D. Once I click the option group button A, the field A will show in my list box. And then if I click button C, the field C in the query would show in the list box. Can you tell me how to make it happen? Thanks!



  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    So you start with a Frame with no default. The user must select one of a,b,c,d.
    You have different sql strings that select the field you want from your table.
    If the user selects A, then you set the rowsource of the listbox to the sql string with the field you want.

    Perhaps you could tell us what you want to do after the field values are in the listbox.

  6. #6
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    OK, after the field value in the listbox, I want to do the multiple selection, the only thing here is I am not sure how to set up the rowsouce to make one list box would display the different value base on different control. I assume it would be done in VBA code, any of you can give me some example on how to write it?

  7. #7
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    I set my rowsouce of the list box by writing the critieria in each field in souce query like:
    IIf([forms]![FormName]![OptionGroup]=1,"*")
    IIf([forms]![FormName]![OptionGroup]=2,"*")
    IIf([forms]![FormName]![OptionGroup]=3,"*")
    IIf([forms]![FormName]![OptionGroup]=4,"*")
    But my listbox return noting in it.....

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    I know the video I mentioned earlier isn't the greatest, but I couldn't find another when I looked.
    If you watch the video, I think you will see the kind of code involved.

    I used the code below to display a set of terms in a combobox.
    To determine what should be displayed, the user selected an OptionButton in a Frame. The value associated with the Option chosen, matched a language identifier.

    Code:
    Private Sub Frame2_AfterUpdate()
        Dim SQL As String
        Debug.Print "value of me.frame2 after update is " & Me.Frame2
        SQL = "select * from (SELECT EntryEF.id, EntryEF.entry, EntryEF.langCode " _
            & "FROM EntryEF Union select  0,'<Please Select>',1 from entryEF " _
            & " Union select  0,'<Choississez>',2 from entryEF " _
            & " UNION select  0,'<OndellexChermigo>',3 from entryEF) where langCode = " _
            & Forms!frmEntriesByLang.Frame2 & " ORDER BY id;"
        Debug.Print SQL
        Me.Combo0.Value = ""
        Me.Combo0.RowSourceType = "Table/Query"
        Me.Combo0.RowSource = SQL
        Me.Combo0.Requery
    End Sub
    The form, the option group and the table are shown in the attached jpg.

    After posting edit: I have tried to delete the jpgs, except for the one showing the combo contents, but haven't figured out how to delete.
    Attached Thumbnails Attached Thumbnails SampleFormWithOptionGroup_and_RelkatedTable.jpg   OptionGroupLanguaaageSample.jpg   SampleFormWithOptionGroup_and_RelkatedTable.jpg  

  9. #9
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Thanks for reply, but sorry, I still don't know how to write SQL for my case.
    Assume I have a option group with button 1, 2, 3 and 4. my query [Place_Result] have fields [country][Province][City][Area]
    While I click on button 1, [Country] in my query would show in my list box [Place_Slc] for further selection.
    If I click on button 2, [Province] in my query would show in my listbox [Place_Slc]
    Can you tell me how to write the SQL to get value in my listbox and eliminate the duplicate data?

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    What is your table? Can you post a copy of your database --remove anything confidential?

  11. #11
    t. hagan is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    7
    Try using the change event to change the rowsource based on your selection in the option group. You can also insert SQL without knowing SQL. Simply change the view in your Access query to SQL view and copy and paste the verbiage.

  12. #12
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    It is worked!!! Thanks, Orange and Hagan, Thank you so much for the help!!!

    Quote Originally Posted by t. hagan View Post
    Try using the change event to change the rowsource based on your selection in the option group. You can also insert SQL without knowing SQL. Simply change the view in your Access query to SQL view and copy and paste the verbiage.

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

Similar Threads

  1. How to Pass ListBox to Function?
    By RedGoneWILD in forum Programming
    Replies: 4
    Last Post: 03-05-2013, 12:13 PM
  2. Replies: 4
    Last Post: 02-14-2013, 09:33 PM
  3. How can I pass the value from a combo box to listbox
    By robertdbuckley in forum Programming
    Replies: 1
    Last Post: 05-24-2012, 08:43 AM
  4. Option Group
    By x__hoE__x in forum Access
    Replies: 2
    Last Post: 12-10-2011, 09:39 AM
  5. Option Group
    By huskies in forum Forms
    Replies: 9
    Last Post: 12-02-2009, 12:06 PM

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