Results 1 to 8 of 8
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Form not acting as Expected


    Hello All,

    I have a form in a new database I am working on and it isn't acting as expected. What I want it to do is check to see if a field contains something and if it does, make it visible, and if it doesn't make it invisible, the code I am using is below.

    It doesn't work however, If I make everything not visible on the form "visible" attribute, everything stays invisible. What am I missing? I haven't seen this type of behavior before. If I put in a stop in the code and check the values while it's running, the values of Ingredient1, 2 & 3 are not null however 4 is null as expected.

    Private Sub Form_Current()



    If Me.Ingredient1 <> Null Then
    Me.Ingredient1.Visible = True
    Me.Ing1Qty.Visible = True
    End If

    If Me.Ingredient2 <> Null Then
    Me.Ingredient2.Visible = True
    Me.Ing2Qty.Visible = True
    End If

    If Me.Ingredient3 <> Null Then
    Me.Ingredient3.Visible = True
    Me.Ing3Qty.Visible = True
    End If

    If Me.Ingredient4 = Null Then
    Me.Ingredient4.Visible = False
    End If


    End Sub


    Thanks in advance

    Dave

  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,652
    That test won't work, think of Null as unknown. Nothing is equal to it, or not equal to it. This tests for both Null and a zero length string:

    If Len(Me.Ingredient1 & vbNullString) > 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    pbaldy,

    Thanks so much, I'll give that a try in the AM

    Thanks

    Dave

  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,652
    No problem Dave, post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    John_G is offline VIP
    Windows 10 Access 2016
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In addition to Paul's note - Each of the tests in your code must have an ELSE block in them to indicate what to do if the fields ARE Null (blank). The visible / invisible properties of the form controls are not reset when you move to another record; the code has to do that. So, using this and Paul's suggestion, your first test might look like this:

    Code:
    If Len(Me.Ingredient1 & vbNullString) > 0 Then
      Me.Ingredient1.Visible = True
      Me.Ing1Qty.Visible = True
    Else
      Me.Ingredient1.Visible = False
      Me.Ing1Qty.Visible = False
    End If

  6. #6
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Thanks guys it worked famously, just as expected.

    John_G, I did originally have the else statement in there but after I got so frustrated with it not working I started to rewrite everything and hadn't put that back in, my foolish mistake.

    I am curious though, why didn't just the check for Null work, like I said, it was seeing that the item was not null?

    Thanks again
    Dave

  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,652
    If you think of Null as unknown, you see that nothing can be compared to it, even another unknown. The test for it could use the IsNull() function, but most of us also test for a zero length string.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Forgot Jason has a faq on Nulls, etc:

    http://www.baldyweb.com/NullEmptyEtc.htm
    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. 2 similar queries acting different....
    By CQCDave in forum Queries
    Replies: 16
    Last Post: 04-29-2015, 01:05 PM
  2. Chart Not acting as you would expect
    By techtony in forum Reports
    Replies: 8
    Last Post: 08-08-2014, 02:22 PM
  3. Crosstab query acting up..?
    By snipe in forum Queries
    Replies: 4
    Last Post: 04-14-2014, 02:35 PM
  4. query is acting up
    By kwooten in forum Queries
    Replies: 20
    Last Post: 12-21-2011, 12:50 PM
  5. Update Query acting up
    By compooper in forum Queries
    Replies: 1
    Last Post: 07-04-2011, 12:27 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