using toggle button in form, to code as 1,0 not -1,0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In an access form, I'm trying to use a toggle buttons, but I'd rather they
code to my database as 1 for yes and 0 for no rather than -1 for yes and 0
for no. Aside from fixing it later, does anyone know how to fix this up
front? many thanks!
 
Hi, John.

Toggle buttons only use -1 and 0, the VB convention for true and false
states, so it can't be set to anything else. It doesn't match other
programming language conventions.

One can always multiply the value of the toggle button by -1 to get a
positive 1 when the state is true (pushed in). Or one may use two unbound
text boxes and use the Raised Special Effect on one text box and the Sunken
Special Effect on the other, then use VBA code to make one text box visible
and the other invisible every time there's an OnMouseDown( ) event over the
visible one, but that's probably more coding than is needed. The simplest
way would be like this:

someValue = ToggleBtn.Value * -1

.. . . where ToggleBtn is the name of the toggle button and someValue is a
variable being assigned a positive 1 when the button is pressed in and 0 when
the button isn't.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
JohnJordan said:
In an access form, I'm trying to use a toggle buttons, but I'd rather they
code to my database as 1 for yes and 0 for no rather than -1 for yes and 0
for no. Aside from fixing it later, does anyone know how to fix this up
front?

You'll have to make the field in the table an Integer
instead of a Yes/No field. Then the check box control on a
form can use a little code in its Click event to set the
value:
If Me.checkbox = -1 Then
Me.checkbox = 1
End If

Make sure the check box's TripleState property is set to No.
 
Hi, John.

That depends upon the situation. If it meant multiplying by -1 in 20
different procedures, then I might think twice about coding for two text
boxes that go visible/invisible to simulate a toggle. However, I'd probably
figure out how to assign the value of the toggle button to a variable in a
single place that would then be passed on to the other procedures, so I would
only have to multiply it in one place, not 20 different places. You can
probably do the same.

You have to consider what makes the most sense and what will require the
least amount of effort for your situation.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Thank you Marshall - I might need a little more guidance - So I right click
on the toggle and then click on properties, then when I click on the 'on
click' category, this is what I get:

Private Sub DFA_Click()

End Sub

So I guess I'm wondering where I add your code... sorry I never really use
visual basic!
 
The code I posted, modified to use your check box's name,
goes between the automatically generated Sub and End Sub
lines.
 
Thanks!

Marshall Barton said:
The code I posted, modified to use your check box's name,
goes between the automatically generated Sub and End Sub
lines.
--
Marsh
MVP [MS Access]

Thank you Marshall - I might need a little more guidance - So I right click
on the toggle and then click on properties, then when I click on the 'on
click' category, this is what I get:

Private Sub DFA_Click()

End Sub

So I guess I'm wondering where I add your code... sorry I never really use
visual basic!
 
Back
Top