Results 1 to 7 of 7
  1. #1
    benthamq is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    32

    Option/Radio Button Problem

    Hello all,



    I have a form that includes an option group (frame) with two radio buttons that correspond to two values in a value list for a table field with a type of text.
    My goal is to have the user's selection determine which of the two text values appears in that field for that record.

    The problem I am encountering is that it seems the radio buttons only return numeric values. I cannot get them to return the correct string to update the record appropriately. One button is returning "1" and the other is returning "2", so instead of the text string I want appearing in that field for the record after update I am getting the number 1 or 2.

    Is it possible for a radio button to return a string? I assume I have to declare a variable and define it as whichever selection is made with the radio button, then convert that into the appropriate string and have that returned but I am really new to VBA and don't really know how to do this; I am toying around and all I get is errors.

    I greatly appreciate any help offered. Thanks very much.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    The OptionGroup control would have to be unbound then use VBA code in some event (such as the OptionGroup AfterUpdate) to save correct string. The string would have to be determined. Something like:

    Select Case Me.OptionGroupName
    Case 1
    Me!fieldName = "ABC"
    Case 2
    Me!fieldName = "DEF"
    Case 3
    Me!fieldName = "GHI"
    End Select

    or use Switch Function:
    Me!fieldName = Switch(Me.OptionGroupName=1,"ABC",Me.OptionGroupNa me=2,"DEF",Me.OptionGroupName=3,"GHI")

    Another option is to use a combobox bound to the field. Item selected from list is saved to field.
    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
    benthamq is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    32
    Thanks.

    That works to correctly update the table with the string instead of the numeric value of the option box.
    But the problem I now have, I assume since it's unbound, is that the form is not saving the record. If I close and reopen the form, or just go to a new record and then go back using the navigation bar on the form, the radio box that was previously selected is unchecked.

    Is there a solution to this?

    Thanks again.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Confused. You say the table is correctly updated so the record must be saving. The OptionBox is unbound so of course it will not show any values from record. If you want to display the string value, use a textbox bound to the field.
    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
    benthamq is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    32
    Sorry for the confusion, what I mean is that the radio button that I click when I open the form in form view is not staying selected if I then close and reopen the form.
    When the form reopens, the radio button I selected during the last time I had it open appears unselected selected.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    The radio buttons and OptionGroup are not bound to any data. They have nothing to show. All they do is trigger the event procedure. If you want the buttons to reflect the data in the table must either bind them and then data would have to be number or use code in the OnCurrent event of form to set the value of the unbound OptionGroup. It would be the reverse of the code to save the string.
    Me.optGroup = Switch(Me!fieldname="ABC",1,Me!fieldname="DEF",2,M e!fieldname="GHI",3)
    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
    benthamq is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    32
    Thanks.

    The best solution, then, seems like it must be to keep the normal numeric data types for the radio buttons, bind the option group to the table field, and just change the data type of the field in the table from text as I formerly had it to number to accommodate the radio buttons value. I have created another table and linked it to that field since the data that I need stored there is text - the radio button values 1,2, and 3 are the primary key of each record in the field of the linked table. The labels on the form will correspond to the values in that table.

    I will mark this solved.

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

Similar Threads

  1. Replies: 6
    Last Post: 07-20-2011, 11:54 AM
  2. Working with Radio Buttons and Option Groups
    By queenbee in forum Access
    Replies: 1
    Last Post: 04-29-2011, 02:25 PM
  3. radio button and checkbox
    By Fifa in forum Access
    Replies: 2
    Last Post: 01-19-2011, 10:20 AM
  4. option group radio buttons
    By ManC in forum Forms
    Replies: 9
    Last Post: 03-08-2010, 03:46 AM
  5. Problem on Option Button
    By cwwaicw311 in forum Forms
    Replies: 2
    Last Post: 02-10-2010, 10:44 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