Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2010
    Posts
    85
    Provided Answers: 2

    Exclamation Unanswered: Show / Hide Command Button

    Hi All

    This should be dead simple, but I can't seem to get it to work. I Have searched previous posts and tried their suggestions but can't seem to find the solution.

    I have a form that contains a number of email fields for each customer.

    I have a button next to each field that I want to become visible if there is an email address in the field (i.e the field is not blank). If the field is blank then the button shouldn't be visible.

    This is the code I am using

    Private Sub Form_Current()

    If Me.EmailAddress.Value = "" Then
    Me.SendMail.Visible = False
    Else
    Me.SendMail.Visible = True
    End If

    End Sub

    The problem appears to be in the checking if the field EmailAddress is blank

    What am I doing wrong??

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Id suggst checking if the column isnull
    Failing that put a breakpoint / watch on the code and make certain its running
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2010
    Posts
    85
    Provided Answers: 2
    Quote Originally Posted by healdem View Post
    Id suggst checking if the column isnull
    Failing that put a breakpoint / watch on the code and make certain its running
    Thanks for the reply.

    Is checking for IsNull the same as having and empty field?

    What would the correct syntax for this be?

    I'm pretty sure it works because if I actually test by placing a value in the field and hard coding the expression

    If Me.EmailAddress.Value = "test"

    Then I can turn the button off.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If isnull(mycolumn) or mycolumn =""
    ...

    Null is not the same as ""

    If you know the function is being called and isnull doesn't work then id start to suspect the data
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2010
    Posts
    85
    Provided Answers: 2
    Your first reply pointed me in the right direction.

    The sample below works just fine!

    Private Sub Form_Current()

    If IsNull(Me.EmailAddress) = True Then
    Me.SendMail.Enabled = False
    Else
    Me.SendMail.Enabled = True
    End If

    End Sub

    Though I still can't figure out why the first approach didn't work.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Though I still can't figure out why the first approach didn't work.
    because "" is not the same as NULL
    you can't test for equality in NULL, all you can do is use the function isNULL

    "" is an empty column, where as NULL means that no value exists for that column
    see:- https://www.google.co.uk/#output=sea...w=1654&bih=885

    you are better off testing for either condition as suggested in post #4, as its conceivable that someone may have their email address deleted over time and the NULL condition will no longer be true UNLESS you set the value as NULL if the length of the string is 0 as part of your update logic
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Sep 2010
    Posts
    85
    Provided Answers: 2
    Perfectly correct. I've made the cahnges and it all works well.

    Thanks again for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •