Results 1 to 7 of 7
  1. #1
    Remillard is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Kelowna, British Columba
    Posts
    14

    Forms, text box only visible when yes/no field checked


    VERY amateur access user here with hopefully an easy question to answer. I have a database tracking staff vehicle information. I have a "Yes/No" field that, depending on its state, I want to display different fields.
    The Yes/No Field is "Warranty". If checked the date field "WarrantyExpires" should be available to complete. If unchecked the date field "SafetyInspection" should be available to complete.
    I was thinking it would start something along the lines of (in the yes/no field's "BeforeUpdate" event):

    Private Sub WarrantyExpire_BeforeUpdate(Cancel As Integer)
    If Warranty = True Then WarrantyExpires.IsVisible = True AND SafetyInspection.IsVisible = False
    If Warranty = False Then WarrantyExpires.IsVisible = False AND SafetyInspection.IsVisible = True
    End Sub

    I have no doubt my syntax is wrong (only scripting I have some level of comfort is Powershell), I just give this as an example of my thinking/logic. I know there's a lot more code that would need to be written, such as "AfterUpdate" events to reflect the change when edited.
    I'm guessing it would also need to be placed in the forms "OnCurrent" event so it changes with each record.

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Remillard is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Kelowna, British Columba
    Posts
    14
    Thanks for the heads up pbaldy. I put the following code in the form's "OnCurrent" event procedure but it's not working right. Should it be in a different field's BeforeUpdate event or AfterUpdate event? Do you use AND statements like I have? Thanks!

    Private Sub Form_Current()
    If Me.Warranty = "True" Then
    Me.WarrantyExpire.Visible = True And Me.SafetyInspection_Date.Visible = False
    Else
    Me.WarrantyExpire.Visible = False And Me.SafetyInspection_Date.Visible = True
    End If
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    Code:
    If Me.Warranty = True Then
      Me.WarrantyExpire.Visible = True
      Me.SafetyInspection_Date.Visible = False
    Else
      Me.WarrantyExpire.Visible = False
      Me.SafetyInspection_Date.Visible = True
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    By the way, you can also use Boolean logic:


    Me.WarrantyExpire.Visible = Me.Warranty
    Me.SafetyInspection_Date.Visible = Not Me.Warranty
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Remillard is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Kelowna, British Columba
    Posts
    14
    Quote Originally Posted by pbaldy View Post
    By the way, you can also use Boolean logic:


    Me.WarrantyExpire.Visible = Me.Warranty
    Me.SafetyInspection_Date.Visible = Not Me.Warranty
    NICE! This worked well. Thanks so much for the support.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help. I wanted to show you the normal way so you'd see the correct structure.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 02-15-2013, 08:44 AM
  2. Display Text Only if Checkbox is Checked
    By Rick5150 in forum Forms
    Replies: 2
    Last Post: 09-16-2012, 09:19 AM
  3. Text Box Value Not Visible
    By twb60 in forum Reports
    Replies: 2
    Last Post: 08-01-2011, 06:41 AM
  4. Replies: 2
    Last Post: 01-06-2011, 04:38 AM
  5. Replies: 1
    Last Post: 09-27-2010, 04:27 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