Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change check box based on change to text box

Status
Not open for further replies.

tvsmvp

Technical User
Aug 17, 2006
59
US
I would like to check a checkbox when I make a change to a corresponding text box. If the text box is empty, I'd like no check, and a I'd like to see a check if anything is in the text box. (Both text box and check box are bound.) I've tried the following code - and it will tick the box - but not "untick" it because apparently it doesn't know when the field is empty. Any suggestions?

Private Sub IndoorArenaDimensions_AfterUpdate()
If IndoorArenaDimensions.Value = "" Then
Me.IndoorArena.Value = 0
Else
Me.IndoorArena.Value = -1
End If

End Sub
 
Hi -
try this:
Code:
Private Sub IndoorArenaDimensions_AfterUpdate()

     If [!]IsNull(Me.[/!]IndoorArenaDimensions.Value = "" Then
          Me.IndoorArena.Value = 0
     Else
          Me.IndoorArena.Value = -1
     End If

End Sub

Hope this helps.

Tom

Born once die twice; born twice die once.
 
Actually, if you're going to use IsNull, you'd need to take the = "" off as well, and add a close parens.

If IsNull(Me.IndoorArenaDimensions.Value) Then
...


If that doesn't do the trick, try this...

If Len(Trim(Me.IndoorArenaDimensions.Value)) = 0 Then
...
 
rjoubert - Oops! I know this and am just a bit distracted at the moment. [blush]


He's right, the code should read:
Code:
If IsNull(Me.IndoorArenaDimensions.Value) Then

And should work.

Tom

Born once die twice; born twice die once.
 
Oh, yes! Works perfect. It's amazing how much you learn with this forum.

You guys rock. Thanks!
 
To test for null, space or zero length:
Me!IndoorArena = (Trim(Me!IndoorArenaDimensions & "") <> "")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top