Full Version: Can you make a check box auto check based off of data being ente
UtterAccess Forums > Microsoft® Access > Access Forms
I have a text box that recives a number to store in a database. The default value is set to null. Next to my text box I have a check box. I want this check box to auto check itself when the user enters a number in the text box next to it. I also want to then be able to uncheck the check box even if there is a number in it.
Any suggestion would be great.
I would use the AfterUpdate event of the text box:
Me.MyCheckBox = True

If the value check box is automatically controlled, it would be considered a calculated value, so, although you do not mention storing it in a field of a table, I want to stress that you SHOULD NOT store the result in a field of a table....(ie: Do not store calculated values!)

So ... with that ... to accomplish your task, which to me seems ... well ... redundant because the user can see whether or not a value is placed in the text box or not! sad.gif ... First you would create a check box on the form, then set the Control Source property of the check box to something like this:

=(Len([NameOfTextBoxThatControlsTheCheckBox] & "") > 0)

What this will is check the length of the value in the check box, if its more than zero, the express will be true, thus "Checking" the box, otherwise, the box will be UN-checked.
O.k. some issues with this...
) I only want the value of the check box to be controled under one condition. The condition is if the value in the text box is not null or above 0 then the value of the check box should be checked. After that I want to be able to uncheck the check box be needed (even if the value is not null or above zero).
The idea is that the text box holds a qty for an order. The check box states if the order is pending or not. I want the auto check becaue I want to take the "opps I forgot to check the pending box" out of the equation.
2) I can't use the Control Source property because the check box is bound to a database field. Reason being is because I need to query pending orders based off of this check box value.
Ok ... then combine the suggestion from Matt and myself ... and use the After Update event of the quantity text box control ...
Text Box named: txtQuantity
Check Box named: chkIsPending
Rule to apply: Modify the pending box after the txtQuanity text box has been modified ... txtQuanity is a Value other than Null, then chkIsPending should be marked as true, otherwise false (this means that ANY value -- even zero --- will cause the check box to me marked. A NULL will clear the check box.
Private Sub txtQuanity_AfterUpdate()
    Me.chkIsPending = (Len(Me.txtQuantity & "") > 0)
End Sub

Quick comment though ... it would seem more intuitive IF you ditched the check box, and used a field like "DateShipped" that a user would enter as they packed/shipped the product ... then all your "Pending" orders can be filtered with (DateShipped Is Null) ... By using this technique, people are MUCH less likely to create errors with data entry.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.