Results 1 to 6 of 6
  1. #1
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46

    Question Making button visible / not visible depending on field criteria

    Hi,



    I have a button named bttn4 on a form which generally is not visible. (The Visible setting on the Property Sheet is set to "No") The button is to open another form when clicked.

    I have a tick box field on the form called [BML Driver]

    If BML Driver is ticked, I want the button to show. If BML Driver is not ticked I want the button to remain hidden.

    I have put the following code on the On Current event ...
    Code:
    
    
    Code:
    Sub Form_Current() 'show bttn4 If Me.[BML Driver] = "yes" Then bttn4.visible = True bttn4.SetFocus Else bttn4.visible = False End If


    The bttn4.visible seemed to work OK, but when I added the criteria of the tick box it stopped working !!!

    Any help or advice would be appreciated.

    Cheers

    Stuart

  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,902
    Would not use "yes" (this is just a string, not a Boolean value). Use True or False, without quote marks. However, don't even need the Boolean constants, just reference the checkbox value because its value would be either True or False.

    Sub Form_Current()
    Me.bttn4.Visible = Me.[BML Driver]
    If Me.bttn4.Visible Then Me.bttn4.SetFocus
    End If

    Advise not to use spaces in any names (nor punctuation/special characters with the exception of underscore).
    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
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46
    That's great June.

    I managed to get there myself just before your reply came in, however once I have the button visible, it is staying visible when I scroll through the records, when really it should disappear on the next record if [BML Driver] is unchecked on the next record.

    Where should I put a bit of code to make the button invisible again ?

    Cheers

    Stuart

  4. #4
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46
    No probs June ~ Just solved it.

    Thanks for your help.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    How did you fix? The button state will be the same for all records because there really is only one button to set property of and that setting will be reflected in all instances of the control.
    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.

  6. #6
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46
    Basically by including the else statement ...

    If Me.[BML Driver] = True Then
    bttn4.visible = True
    bttn4.SetFocus

    Else
    bttn4.visible = False

    End If

    This seems to fix it, but it may create other issues I am not yet aware of !!!

    Stuart

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

Similar Threads

  1. Replies: 4
    Last Post: 11-04-2014, 07:35 PM
  2. Replies: 18
    Last Post: 04-08-2011, 09:20 PM
  3. Replies: 2
    Last Post: 04-04-2011, 02:18 PM
  4. Making subform field visible/invisible
    By Snufflz in forum Forms
    Replies: 3
    Last Post: 01-17-2011, 05:30 AM
  5. Replies: 2
    Last Post: 01-06-2011, 04:38 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