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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a checkbox appear only if a textbox has data 1

Status
Not open for further replies.

Ravensleach

Programmer
Oct 19, 2004
45
PE
Hi guys

I have a form with two checkbox fields and a date field

chkHonorary
chkLife
txtFullDate

I would like to make the checkboxes functional only when the text box is not null.

(this is in Access 2000 9.0.2720)

I’ve tried the solution offered in thread702-909430 but it’s not working (stays invisible). Is AfterUpdate the wrong event?
----------------------------
Private Sub txtFullDate_AfterUpdate()

If IsNull(txtFullDate) Then
chkHonorary.Visible = False
Else
chkHonorary.Visible = True
End If

End Sub
-----------------------
Maybe I should add I can’t use enabled/not enabled controls as the main database user is partially sighted so greyed out stuff is a no-no. Thanks
 
Have you tried this code in both the Current event procedure of the form and the AfterUpdate event procedure of the txtFullDate control ?
chkHonorary.Visible = Not IsNull(txtFullDate)
chkHonorary.Enabled = chkHonorary.Visible

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
How are ya Ravensleach . . . . .

Try this:
Code:
[blue]   If Len(txtFullDate & "") = 0 Then
      chkHonorary.Visible = False
   Else
      chkHonorary.Visible = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Woops . . . . submit too soon . . .

Remove you code and put the following in the code module of the form:
Code:
[blue]Public Sub ChkVisibility()
   
   If Len(txtFullDate & "") = 0 Then
      chkHonorary.Visible = False
   Else
      chkHonorary.Visible = True
   End If

End Sub[/blue]
Then in the [blue]On Current event of the form[/blue] and the [blue]After Update event of txtFullDate[/blue], add the following code:
Code:
[blue]ChkVisibility[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks a lot; used Phv's solution because I tried it first and it works, thank you both.
 
When you all are talking about "chkHonorary" and "txtFullDate" are you talking about the actual control source name or are you talking about the text box/ check box name?
 
It's the name of the text box or check box. I'm not that great at code, but I guess since I was manipulating a form and its controls, that's what the code has to point to, rather than the table fields which actually contain the data.
 
I should be able to reverse it if I want the oposite right? Cause I'm tring to check a check box and have a field appear.
 
Yes, I would think that if you swapped the form controls it would work; the "No" value for a checkbox is 0 and the "Yes" is -1

So, if checkbox is 0 then text.visible is false
if checkbox is not 0 then text.visible is true

Give it a try - I'd be interested to know if it works.
 
I ended up using, and put it in the Form_Current() and chkCallBack_AfterUpdate():

If (chkCallBack) = No Then
txtCallBackNfo.Visible = False
Else
txtCallBackNfo.Visible = True
End If

And I just put the default value of the check box set to No. Worked like a charm.
 
Is there anyway I can do the same thing with a button or a toggle button? I want to display different inputs for a sale or for a call back.
 
I would think toggle buttons would be easier, because it works in the same -1,0 yes/no, on/off way as a checkbox. If you can get it work with an option group that would probably be better, so only one could be selected. Option group values are 0=nothing selected, 1=first option, 2=second option, etc.

For a command button, you'd need code for the OnClick event, with normal state being invisible for the text box(es).

If you want to show several form controls for a sale or callback, it might be better to design two new popup forms each with their own command button. For many data inputters this would be more intuitive, would demarcate the processes more clearly. Perhaps if you have time test both methods?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top