Results 1 to 9 of 9
  1. #1
    tm1274 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    15

    Field Visibility Based on Yes/No Option Group

    Hello Everyone. I am working on a small database that currently has a single form with a yes/no option group named "ROption" and I would like to make a text box, named "RMargin" visible if the option "No" is selected in the group but make the text box "RMargin" invisible if the user selects "Yes" in the option group "ROption".
    I cannot find a good example online to make it work correctly and was wondering if someone would have an example I could look at to see how it should be coded? This is what I have but it only makes the text box invisible if "Yes" is selected but does not make it visible when "No" is selected.



    Code:
    Private Sub ROption_AfterUpdate()
    If Me.ROption = "No" Then
    Me.RMargin.Visible = True
    Else
    Me.RMargin.Visible = False
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    You mention textbox RMargin but code shows RetailMargin.
    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
    tm1274 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    15
    You are correct. I was typing something in another application and switching back and forth and somehow inadvertently typed "Retail" in the code. I have corrected it in my original post. Thanks for pointhing that out.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Option Group takes value of selected RadioButton (or checkbox or toggle). This value would be a number, not text. Why do you use "No"?

    What values do you assign to each RadioButton - 1 and 2? Reduce code to one line:

    Me.RMargin.Visible = Me.ROption = 1

    Or 0 and -1

    Me.RMargin.Visible = Not Me.ROption

    All records will apply same setting because there is only the one RMargin textbox. This may be confusing for users if form is in Continuous View (or maybe they will be just fine). Conditional Formatting could dynamically enable/disable textbox for each record all at once.
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    If you used Boolean you could get away with

    Code:
    Me.RMargin.Visible = Not ROption
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    tm1274 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    15
    I have very little coding experience. I have looked on the web for examples and seen 1 and 0 used but also saw an example where words were used instead, so I thought either was fine.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    If you saw words then likely some code was taking the number value and translating to text. Would be interested in seeing the example you found.
    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.

  8. #8
    tm1274 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    15
    Hello June7. Your code
    Code:
    Me.RMargin.Visible = Me.ROption = 1
    worked perfectly. I have visited a lot of sites so I don't which had the code I saw the text but I will go through my history and let you know if I can find it again. I really appreciate your assistance with this specific issue.

  9. #9
    tm1274 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    15
    No luck on the website with the text on the option group but if I do find it later I will post a link.

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

Similar Threads

  1. Replies: 8
    Last Post: 12-13-2016, 02:11 PM
  2. Replies: 5
    Last Post: 07-11-2013, 02:19 PM
  3. Field visibility based on ComboBox selection
    By cactuspete13 in forum Forms
    Replies: 3
    Last Post: 01-30-2013, 03:37 PM
  4. Replies: 3
    Last Post: 12-02-2012, 09:38 AM
  5. Replies: 3
    Last Post: 01-13-2011, 03:53 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