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!

help with disabling a checkbox when a textbox is 0 or null 2

Status
Not open for further replies.

cbearden

Technical User
May 17, 2004
80
US
I'm guessing that this will take coding and I don't know coding very well. I have 4 categories...I'll call them A B C D.
For each category, there is 3 text boxes, EX: A Cost, A Refund, A Rec Date
I will have a checkbox for when each is rec. but not all accounts will have every category(A, B, C, D). I'm trying to get the checkboxes for each category to be disabled if and only if the Category(A, B, C, D) Cost is NULL or 0.

Thanks in advance for the help.
 
I assume you have a form that has all of these controls and that your form has a recordsource and you navigate through your records. If so, then you could add the following code into your 'Form_Current' event.
If IsNull(Me.Recordset!Cost) or Me.Recordset!Cose = 0 Then
Me.Check1.Enabled = False
Else
Me.Check1.Enabled = True
Endif


Code: Where the vision is often rudely introduced to reality!
 
I will try this and hopefully I'll get it to work. Thank you very much!
 
Hi, cbearden,

Okay, just to make sure I understand... 12 total textboxes and 12 total checkboxes, each checkbox corresponding to a textbox, but divided into 4 categories. And if there is a value in any textbox within a category, all the checkboxes for that category are enabled. Have I got that right? So, for instance, if textbox 2 (category 1) has a value, checkboxes 1-3 are enabled? And if textboxes 4-6 (category 2) are null or zero, checkboxes 4-6 are disabled?

Ken S.
 
No, there are only 4 checkboxes

4 Categories - A B C D
3 Textboxes per cat - Cost, Refund, RecDate
1 Checkbox per Cat

Here's what it looks like

Acost
Arefund
Areceive
Achkbox

Bcost
Brefund
Breceive
Bchkbox

Ccost
Crefund
Creceive
Cchkbox

Dcost
Drefund
Dreceive
Dchkbox

Ex: If Dcost is 0.00 or NULL, Dchkbox needs to be disabled.

Thanks!
 
Me!Dchkbox.Enabled = (Nz(Me!Dcost, 0) <> 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
where would i put the code?
also...what is Me in Me!Dchkbox? the form name?

Thanks
 
Hi, cbearden,

No, Me is a self-reference to the form. It is equivalent to Forms!FormName.

As to where you would put the code - in an event procedure on the form's OnCurrent event, and in the AfterUpdate event for each of the textbox controls.

Ken S.
 
Thank you all for the help! I got it to work. Again thank you thank you thank yoU!!!!!
 
Ran across one problem.
What I did was put the code in two spots, the forms OnCurrent and the chkbox's AfterUpdate. I go into the form and when I type in 0, the refund, rec, and chkbox all disable but when I type in a value, for instance, $500.00, it does not do anything...UNTIL...I hit design view and then hit Form view. Then it will enable all 3 fields.
Am I missing something?

Thanks
 
Yes. The checkbox Visible property does not rely on the checkbox data, it relies on the presence or absence of data in the textbox fields. So the code should go in the AfterUpdate event of the textboxes.

Ken S.
 
I put the code in the AfterUpdate of the textboxes but it does nothing. Also, every other record the fields are disabled when they all should be. !?!
 
cbearden, I misspoke in my previous post, you don't need the code in the AfterUpdate of each textbox, just the cost textboxes. Here's what your form's module should resemble:
Code:
Option Compare Database
Option Explicit
-----------------------------------------
Private Sub Form_Current()
Me!Achkbox.Enabled = Nz(Me!Acost, 0) <> 0
Me!Bchkbox.Enabled = Nz(Me!Bcost, 0) <> 0
Me!Cchkbox.Enabled = Nz(Me!Ccost, 0) <> 0
Me!Dchkbox.Enabled = Nz(Me!Dcost, 0) <> 0
End Sub
-----------------------------------------
Private Sub Acost_AfterUpdate()
Me!Achkbox.Enabled = Nz(Me!Acost, 0) <> 0
If Me!Achkbox.Enabled = False Then
    Me!Achkbox = False
End If
End Sub
-----------------------------------------
Private Sub Bcost_AfterUpdate()
Me!Bchkbox.Enabled = Nz(Me!Bcost, 0) <> 0
If Me!Bchkbox.Enabled = False Then
    Me!Bchkbox = False
End If
End Sub
-----------------------------------------
Private Sub Ccost_AfterUpdate()
Me!Cchkbox.Enabled = Nz(Me!Ccost, 0) <> 0
If Me!Cchkbox.Enabled = False Then
    Me!Cchkbox = False
End If
End Sub
-----------------------------------------
Private Sub Dcost_AfterUpdate()
Me!Dchkbox.Enabled = Nz(Me!Dcost, 0) <> 0
If Me!Dchkbox.Enabled = False Then
    Me!Dchkbox = False
End If
End Sub
Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top