Conditionally Visible
April 29, 2009 7:22 AM   Subscribe

Is there a way to make a command button on a form in MS Access 2003 conditionally visible?

Desired behaviour: if a text box on the form is null, the command button should be visible, otherwise invisible. Bonus points if this can be done in the control's properties as I am a noob to code, but I may be able to correctly use any VBA suggestions. I did search the googles unsuccessfully.
posted by preparat to Computers & Internet (4 answers total) 1 user marked this as a favorite
 
If IsNull(txtBox) Then
cmdButton.Visible = False
End If
posted by okbye at 7:32 AM on April 29, 2009


Best answer: So it's visible/not visible based on the text box at load? Add an event to activate on the form loading:

Private Sub Form_Load()

If IsNull(txtBox) Then
cmdButton.Visible = False
Else
cmdButton.Visible = True
End If

End Sub


If someone can edit the text box on the form, and you want the button to show up, then you'll want the code to be part of an "After Update" event on that text box (I think) in addition to on the form load.
posted by inigo2 at 7:38 AM on April 29, 2009


Response by poster: Thank you okbye and inigo2! I think the "After Update" event on the text box is what I need.
posted by preparat at 7:42 AM on April 29, 2009


Thinking about it, "After Update" might just do it once the person clicks out; "On Dirty" might help, too. (I do a lot of trial and error in Access.....)
posted by inigo2 at 7:47 AM on April 29, 2009


« Older Best PS3 Games on PSN?   |   Dating a hippy? Newer »
This thread is closed to new comments.