I have a Toggle Button control on my form. I would like to make the "Control Source" of the toggle button based on whether or not a certain text box on my form contains a value. Is this possible?
For Example, The Toggle Button source would be
-1 if a different text box contains data.
Not quite sure where you are headed....
You say "Toggle Button" and "Control Source", so it sounds like you have a toggle button that is not in a frame (option group). "Control Source" refers to the field in the current recordsource that the toggle button is bound to.... so having a "control source" of -1 (True) does not make sense.
You can make the toggle button change state to show untoggled/up/0/FALSE or toggled/down/-1/TRUE by checking if the text box has an entry using the form's Current event:
Code:
Private Sub Form_Current()
Me.Toggle12 = Len(Me.Text14)
End Sub
(You would also need code in the text box after update event to set the state of the toggle button after editing the text box.)
-------------------
The way the code works is that if the length of the value of the text box is zero, the value of the toggle button is set to FALSE (zero/button up). If the value of the text box is not zero, the value of the toggle button is set to TRUE (-1/button down).
FALSE is defined as a zero state. TRUE is defined as Not FALSE (ie not zero). So anything that is not zero is True... doesn't matter if it is positive or negative, it is still True.
"TRUE", in Access, is defined as -1.
"TRUE", in Excel, is defined as +1.
If you use TRUE and FALSE in code, the code is transferable between Access and Excel without modification. If you hard code -1 or 1 you will have errors or unexplained errors / values.
Does this help?