Results 1 to 6 of 6
  1. #1
    johnrohan is offline Novice
    Windows 10 Access 2007
    Join Date
    Aug 2017
    Posts
    15

    Getting a yes/no control to enable another form field

    Hello group, you have never failed to be helpful, so I have another question. This is one of those issues that should be super easy, but it isn't.


    To put it as simply as possible, I want the user to have to check the "Yes" box on the form, in order to enable text input on another text field on the form.


    So I set up a little option group on my form ("Frame_475"), with simple yes/no option buttons. The default is "no". Another text box on the form ("Master Task") is disabled by default, unless the person chooses "yes", then that field is enabled for them to enter information.


    So I set up this code in the Frame_475 After update:
    _____________________________________________
    Private Sub Frame475_AfterUpdate()




    If (Me.Frame475.Value = False) Then

    Me.[Master Task].Enabled = False

    Else

    Me.[Master Task].Enabled = True

    End If


    End Sub
    ______________________________________

    It works - partially. Basically it works right off the bat, but when I change the box on any record from No to Yes, then the [Master Task] field is enabled on ALL records! Obviously that wasn't my intent. It should only work on the current record. I have tried this code as a before event, and after event. I have tried it both on the option group, and on the text field. I have tried using "Value=0" instead of "Value=false". All had similar buggy results.

    I have also tried it in the On Load event for the form itself, but in that case it didn't do anything at all.

    What am I missing here? Any suggestions?

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    When you move to the next record, set both fields back to their default values. This will be in the form's AfterUpdate event.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    You'd need code in the current event of the form to handle moving from record to record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    when I change the box on any record from No to Yes, then the [Master Task] field is enabled on ALL records!
    That's normal behaviour - the properties of the textbox are part of the form, and are not directly dependant of the record the form is displaying.

    It should only work on the current record.
    This is easily done by using the On Current event of the form.

    If the yes/no option is bound to field in the form's data, just put the same 5 lines you have above into that event as well.

    If the yes/no option is unbound, then just put these two lines into the On Current event:

    Frame475 = False
    Me.[Master Task].Enabled = False

    What these do is reset these two fields to the "default" value of False every time you move to a new record.
    But, what do you want to do if you move to a record that already has a value in [Master Task]?

  5. #5
    johnrohan is offline Novice
    Windows 10 Access 2007
    Join Date
    Aug 2017
    Posts
    15
    Quote Originally Posted by John_G View Post
    If the yes/no option is bound to field in the form's data, just put the same 5 lines you have above into that event as well.
    Yay!! that worked, thanks!

    But, what do you want to do if you move to a record that already has a value in [Master Task]?
    It doesn't really matter in this case. The value is visible whether it's been disabled or not. And people will be only using the form for data entry, not other sources, so it shouldn't be an issue anyway.

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Glad we could help. Good luck with your project - don't hesitate to ask if you need assistance.

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

Similar Threads

  1. Enable/Disble a control for data entry
    By PinkLady50 in forum Forms
    Replies: 4
    Last Post: 06-26-2017, 07:43 PM
  2. Replies: 2
    Last Post: 05-28-2015, 12:12 PM
  3. Replies: 13
    Last Post: 11-11-2014, 02:43 PM
  4. Replies: 4
    Last Post: 03-05-2013, 09:03 AM
  5. Enable Field off Text Box
    By SpdRacerX in forum Forms
    Replies: 5
    Last Post: 03-13-2012, 01:48 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