Results 1 to 5 of 5
  1. #1
    mcw176 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    6

    Option Group Radio Buttons: Number to Text using Visual Basic

    I am attempting to save information from option group radio buttons into the form's table and the underlying table as text instead of numbers. I have been moderately successful so far; as long as the user clicks the "Enable Content" button when Access opens, when they click the specific radio button, that text will be entered into both the form's table and the underlying table. However, the button grays out - there is no evidence that it was clicked.


    I would like to have the button appear and stay selected.
    My option group is named StudyTypeFrame, and the Control Source is the field StudyType on the underlying table. My code looks like this:

    Private Sub StudyTypeFrame_AfterUpdate()
    Select Case Me.StudyTypeFrame
    Case 1
    Me.StudyType = "GN Clinical Trial Research"
    Case 2
    Me.StudyType = "SNN Clinical Trial Research"
    Case 3
    Me.StudyType = "Clinical Research"
    End Select
    End Sub

    I am very new to Access, and beyond adapting this code for my form after finding something similar in one of the forums, I have no coding experience. Any advice would be wonderful!

    If the radio button->text association is too impractical, I have another question. If the radio buttons save numbers as they normally do, is it possible to use those numbers to determine text in another field? For example, if button "1" is clicked and the underlying table displays the "1", is there a way to say "if [fieldname a] = 1, then [fieldname b] = text1" ?

    Thank you so much!

  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,945
    Don't understand why the button greys out.

    Yes, an expression in textbox can return alias, like:

    =Choose([StudyType], "GN Clinical Trial Research", "SNN Clinical Trial Research", "Clinical Research")

    An alternative is a combobox or listbox with the 3 options.
    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
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    First, if the underlying field is numeric, as you were suggesting, then just change the frame's ControlSource to that field. Assuming the wording of the Radio Buttons is your three different values, then you're done. Get rid of the AfterUpdate code. (The Frame may have been greying out because it isn't bound to anything.)

    Typically, you would also add a small table to your database that has two fields - the key value (1-3) and the wording for that item. This will help you put the words on a report (rather than the key numbers) using a lookup feature or a join. for example, the table could look like this:
    Code:
    tblStudyType
    StID      PK (primary Key - 1 to 3)
    StName    TEXT (the names)
    Or, you could use June7's code everywhere you want to translate back from the number.

    Once you have that table, you could also replace the radio buttons with a combobox. The combo box would be bound to the underlying field, have two columns, and you'd set the properties like this
    Code:
    Column Count     2
    Column Width     0";2"
    Control Source   [StudyType]   (name of the underlying field)
    Row Source to    Select tST.[StID], tST.[StName] from tblStudyType AS tST ORDER BY tST.[StID];

  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,945
    A combo or list box can also have a Value List as RowSource, table not needed. Not advised if the list frequently changes.
    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
    mcw176 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    6
    Thank you June7 and Dal Jeanis!

    June7, I did use your code in a text box in the form, but I would have wanted to link that back into the table as well, and I wasn't sure how to do that; I decided to try a second option before I asked.

    Dal Jeanis, I followed your advice about the second table. I created a one-to-many relationship between the Primary Key of the StudyType table and the StudyType# stored by the radio buttons in the main table. I then created a query incorporating the two. Finally, when I was writing my report, I drew fields from the two different tables as necessary. I can't say that I fully understand why it works, but I have a basic idea and I'm pleased with the result.

    I appreciate you're advice about the combo boxes -- I've used several already, and I know they would be SO much easier, but my boss said she prefered the aesthetic of the buttons.

    Thank you two so much - I'm so glad I was able to figure everything out this quickly

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

Similar Threads

  1. Radio buttons within Option Group not working
    By losingmymind in forum Programming
    Replies: 7
    Last Post: 01-09-2013, 03:09 PM
  2. Creating Buttons on a form keeps returning a visual basic error
    By Robin Banks in forum Database Design
    Replies: 1
    Last Post: 02-28-2012, 07:48 AM
  3. Replies: 6
    Last Post: 07-20-2011, 11:54 AM
  4. Working with Radio Buttons and Option Groups
    By queenbee in forum Access
    Replies: 1
    Last Post: 04-29-2011, 02:25 PM
  5. option group radio buttons
    By ManC in forum Forms
    Replies: 9
    Last Post: 03-08-2010, 03:46 AM

Tags for this Thread

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