Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2020
    Posts
    5

    Problems trying to hide a command button

    Windows 10, 64-bit, MS 365




    Hi - I'm very much a novice and am probably trying to run before I can walk, but I'd like to hide a button if a field is empty. I think I've got the expression below correct, but when I define it as OnCurrent, the button remains visible. From other posts here, it looks as if that's the right place to make the button invisible, but what am I doing wrong, please?!

    Code:
    =IIf(IsNull([WorkWhereSeen]),[cmdViewWorksWhereSeen].[Visible]=False)
    Thanks, Sam

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Use If...Then instead of IIf, For example

    Code:
    If Nz(WorkWhereWhen,L')="" Then cmdWorkWhereWhen.Visible=False
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    or just

    cmdWorkWhereWhen.Visible=nz(WorkWhereSeen,"")<>""

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by AndThePharaohs View Post
    Windows 10, 64-bit, MS 365


    Hi - I'm very much a novice and am probably trying to run before I can walk, but I'd like to hide a button if a field is empty. I think I've got the expression below correct, but when I define it as OnCurrent, the button remains visible. From other posts here, it looks as if that's the right place to make the button invisible, but what am I doing wrong, please?!

    Code:
    =IIf(IsNull([WorkWhereSeen]),[cmdViewWorksWhereSeen].[Visible]=False)
    Thanks, Sam
    I think you might need the code you've been given in the forms On Current event and in the After Update event of WorkWhereSeen
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Jul 2020
    Posts
    5
    Thanks to all for the various suggestions, but I've had a play with them to no avail - even after correcting the names! ;-) It's definitely pure iggorance on my part - if it could be done in Perl, I'd be fine, but could I presume to ask if you could put the code into the attached file and I can then pore over it to see what I've been doing wrong.

    The form is frmWorkFullCol and record 6 doesn't have either location (WhereSeen and PermHome), so both buttons should vapourise, as I've got code for both in there now.

    Thanks also to Micron for the attach instructions - it wasn't obvious!
    Attached Files Attached Files

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Try the db attached:
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Placing the IIf statement in the property sheet was incorrect.

    As the code needs to be used in both the form current event (so it is checked on each record change) & in the after update event of both textboxes, I've added a procedure called CheckControls which is then called from each of those places. The code is:
    Code:
    Option Compare DatabaseOption Explicit
    
    Private Sub CheckControls()
        
    If Nz(WorkWhereSeen, "") = "" Then
        cmdViewWorksWhereSeen.Visible = False
    Else
       cmdViewWorksWhereSeen.Visible = True
    End If
    
    If Nz(WorkPermHome, "") = "" Then
        cmdViewWorksPermHome.Visible = False
    Else
       cmdViewWorksPermHome.Visible = True
    End If
    
    End Sub
    
    Private Sub Form_Current()
        CheckControls
    End Sub
    
    Private Sub WorkPermHome_AfterUpdate()
        CheckControls
    End Sub
    
    Private Sub WorkWebPage_AfterUpdate()
        CheckControls
    End Sub
    See attached for the updated version of your app
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    Join Date
    Jul 2020
    Posts
    5
    Many thanks, Colin (or Isla - I love the nickname!) - that works a treat! There's no way I'd have come up with that, but I'll study it and learn. Cheers!

  9. #9
    Join Date
    Jul 2020
    Posts
    5
    Hi Bob,

    I've only just seen your reply after downloading and looking at Colin's, but I'll investigate yours as well.

    I've now had a look - I had to add an Else so the button was visible for the next record, but it also works a treat.

    Many thanks.

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    On behalf of us all, you’re welcome. Indeed the most important thing you can do is study the code and learn. Also try using the code Ajax supplied which is more concise

  11. #11
    Join Date
    Jul 2020
    Posts
    5
    I have been out all day and only just tried this out - and it works fine, thanks! As an erstwhile Perl and APL hacker, I much appreciate the brevity, although I'll keep a record of all three suggestions - as the Perl saying goes, there's always another way to do it! Thanks again.

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

Similar Threads

  1. Hide a command button
    By WendellS in forum Macros
    Replies: 5
    Last Post: 03-06-2019, 02:35 AM
  2. Hide command button on form from certain users
    By Delfina in forum Programming
    Replies: 5
    Last Post: 02-16-2019, 08:06 PM
  3. Hide command button on form from certain users
    By Delfina in forum Programming
    Replies: 9
    Last Post: 02-09-2019, 07:36 PM
  4. Replies: 1
    Last Post: 10-27-2016, 10:51 PM
  5. Replies: 2
    Last Post: 06-06-2012, 10:53 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