Results 1 to 6 of 6
  1. #1
    rad1182 is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    10

    Button Hidden When Field Is Null

    Hello Everyone,

    I have a form that has a field called LastName and a button called CmdEdu, which opens ups another form.

    I want the CmdEdu button to be hidden whenever the LastName field is null.

    I've tried a code in Form_Current() and it works in hiding the button when the field is null, however whenever I type something into the LastName field and then tab over to the next field, the button doesn't appear.

    The code is:



    If Nz(Me!LastName, "") = "" Then
    Me!CmdEdu.visible = False
    Else
    Me!CmdEdu.visible = True
    End If

    Thanks in advance.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Try this: the Cuirrent event is the right spot.

    If IsNull(Me!LastName) OR _
    Len(Me!LastName & "") = 0 Then
    Me!CmdEdu.visible = False
    Else
    Me!CmdEdu.visible = True
    End If

    Should pick up Null and zero length string, I think

  3. #3
    rad1182 is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    10
    Hey orange, thanks for the suggestion, but the same thing happens. The code does hide the button, but when I fill in the LastName field and then tab over to the next field, the buttons are still hidden. If I save the record, scroll to a previous record, then go back to this one then the button does appear. However, I want the button appear as soon as I tab over from the LastName field. Any suggestions on how to do this would be greatly appreciated.

    Thanks again.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Try putting the same code in the AfterUpdate event of the LastName control.
    What exactly are you doing when you say "then tab over to the next field"?
    Are you entering a lastname value then moving to the next control?

    You may have to do a Me.Requery.... hmmm not sure. Try without, or try with in the AfterUpdate of the Lastname control

  5. #5
    rad1182 is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2011
    Posts
    10
    Yes, moving on to the next control...that's what I meant.

    Putting the same code in the AfterUpdate event of the LastName field works. Thanks for the help!

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849

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

Similar Threads

  1. If/Then Null based on Null Value of Another Field
    By vbpeterson in forum Queries
    Replies: 11
    Last Post: 06-05-2012, 05:00 PM
  2. Replies: 3
    Last Post: 05-09-2012, 04:04 PM
  3. Replies: 1
    Last Post: 09-15-2011, 08:45 AM
  4. Replies: 6
    Last Post: 07-20-2011, 11:54 AM
  5. Replies: 0
    Last Post: 01-18-2011, 07:09 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