Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68

    How to sort using radio buttons?

    Hi!



    I have a sorting-question, but first the design of my db...

    In my database with equipment I have a checkbox telling if the product is in use or if it's archived. The value is '-1' if it is in use and '0' if it is archived.

    I use a form to list and sort out items using textboxes and drop downs. I fill out the form and hit "Search" to sort and show the equipment based on the criteria in the form. I do this using a query connected to the database.

    I would like to add three radio buttons to the search form to select "all equipment", "equipment in use" or "archived equipment" when I sort. I use the wizard to create the radio buttons and give the values -1 and 0 to the two latest chioces, but what about the "all equipment" chioce!?

    The form works fine with the "equipment in use" and "archived equipment" but I have to assign the "all equipment" a value. And what do I write as conditions in the query?
    Right now I write...

    LIKE [Forms]![frmSearch].[fActive1] & "*"

    ...where [fActive1] is the group of the three radio buttons.

    I hope I wrote this understandable for you. If not, please ask if anything is un clear!

    Thanks!

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I usually do this by modifying record source of the list box/combo box.

    So let's say you want to search your in use items only but your default is all items

    so let's say your default is SELECT * FROM tblEquipment

    when you click your radio button and then your search button you would have something like


    Code:
    if chkActive = -1 then
       ComboBoxName.RecordSource = "SELECT * FROM tblEquipment WHERE ([InUseFlag] = -1)
    elseif chkInActive <>-1 then
       ComboBoxName.RecordSource = "SELECT * FROM tblEquipment WHERE ([ArchivedFlag] = -1)
    else
    ....
    endif
    of course you'll have to substitute your actual object names to make it work.

  3. #3
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    So where do I type this? In the event for clicking the search button? Not in the design view for the query?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    correct, the on click event of your search button.

  5. #5
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    I write this but get runtime error 424... Help!

    If fActive1 = -1 Then
    qrySearch.SourceObject = "SELECT * FROM tblUnit WHERE ([InUse] = -1)"
    ElseIf fActive1 = 0 Then
    qrySearch.SourceObject = "SELECT * FROM tblUnit WHERE ([InUse] = 0)"
    ElseIf fActive1 = 1 Then
    qrySearch.SourceObject = "SELECT * FROM tblUnit WHERE ([InUse] < 1)"
    End If

    FYI...
    -1 = in use
    0 = not in use
    1 = all equipment

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if factive1 is a radio button you have too many states. Radio buttons are either -1 (yes) or 0 (no).

    If you have three states you probably want an OPTION GROUP not a simple radio button.

    The option group would allow you to have what appear to be radio buttons but whenever you click on one of the options it removes the marker from the other two options so only one is valid at a time.

    Secondly, I've never used .sourceobject so I don't know if that's causing your problem. When I want to change the contents of a list box/combo box I always do use the objectname.recordsource = <new query>. Try fixing the first item and see if you still have trouble. If you do try using the .recordsource property instead of .sourceobject.

  7. #7
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    I'm sorry, but it actually is an option group I'm using. I just wasn't clear with that ^^ Those "radio buttons" have the values -1, 0, 1 as in my previous post.

    I tried with .RecordSource but it didn't work and it's not in the list of options to chose from.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    is qrysearch the name of an object (list box, combo box) on your form? or is it the name of a query in your database?

    it's got to be the name of an object on your form for the .recordsource property to be available.

  9. #9
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    I have the form "frmSearch" where I have the search function. In frmSearch I have a sub form (frmSearchSub) containing the sorted out data.

    When you open the form every parameter is set to null and every post in the db i showed. When I make my search criteria and hit the search button the frmSearchSub is updated via a query (qrySearch) that is activated by the button.

    Is that an answer to your question?

  10. #10
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    then you'd want something in your ON CLICK event like:

    Code:
    If fActive1 = -1 Then
    frmsearchsub.recordsource = "SELECT * FROM tblUnit WHERE ([InUse] = -1)" frmsearchsub.requery
    ElseIf fActive1 = 0 Then
    frmsearchsub.recordsource = "SELECT * FROM tblUnit WHERE ([InUse] = 0)" frmsearchsub.requery
    ElseIf fActive1 = 1 Then
    frmsearchsub.recordsource = "SELECT * FROM tblUnit WHERE ([InUse] < 1)" frmsearchsub.requery
    End If
    You still have a logical inconsistency though, unless your factive1 = 1 is intended to show ALL records.

  11. #11
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    When fActive1 = 1 all posts will be shown.

    Now I get the error: "Method or data member not found" and VB marks the first ".RecordSource".

  12. #12
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I may have the incorrect syntax it may be something like

    me!mainformname.subformname.recordsource = "blah"

    I usually do this sort of thing with list boxes not subforms.

    If you can provide a sample of your database I can take a look.

  13. #13
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    Double post...

  14. #14
    PoorCadaver is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Oct 2011
    Posts
    68
    There you go. Didn't have time to make it neat so just cklick your way through the error messages until you come to the form!
    Attached Files Attached Files

  15. #15
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Here's a copy of your database back. The correct syntax is:

    Me!SubformName.form.recordsource = "SQL STATEMENT"

    DB SAMPLE 1.0.zip

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Radio Buttons
    By maguyver in forum Access
    Replies: 3
    Last Post: 07-07-2012, 10:39 AM
  2. Radio Buttons
    By ccordner in forum Forms
    Replies: 1
    Last Post: 01-27-2012, 09:56 AM
  3. Radio Buttons
    By neil123williams in forum Forms
    Replies: 8
    Last Post: 11-11-2011, 03:38 PM
  4. what happened to radio buttons?
    By judomum in forum Forms
    Replies: 1
    Last Post: 10-09-2011, 11:58 AM
  5. radio buttons from 97 to 2010
    By mmm in forum Access
    Replies: 0
    Last Post: 12-03-2010, 04:20 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