about 2 toggle buttons

G

Guest

hi, good day.

i have made 2 toggle buttons toggling each other when clicked respectively.
here is its newbie code:

Private Sub Toggle20_Click()
If Toggle21 Then
Toggle21 = False
Toggle20 = True
Else
Toggle21 = True
Toggle20 = False
End If
End Sub

Private Sub Toggle21_Click()
If Toggle20 Then
Toggle20 = False
Toggle21 = True
Else
Toggle20 = True
Toggle21 = False
End If
End Sub

Private Sub Form_Open(Cancel As Integer)
Toggle21 = True
Toggle20 = False
End Sub

i have used this code before and it worked on common circumstances.

in my problem, i made a continuous form and have set its allow additions
property to No. the toggle buttons are located at the form footer. in this
situtation, my code only works when the form already contains records. if i
clear the records and open it in form view (e.g. new list of the new day),
only the toggle button that i clicked will be pressed down or up. meaning,
the code was not executed.

it sure works again if i set the allow additions property to Yes. but i
dont want it to allow additions coz i want the form as a list only. i have
set its controls read only.

what did i miss? any recommendations?

thanks.
 
A

Allen Browne

wendell, if your aim is that clicking either button releases the other, why
not put the 2 buttons in an option group? No code needed.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:D[email protected]...
 
G

Guest

yeah, i have tried that already and it worked.

i really dont know but maybe it is just my preference to use toggle over
option group. would it be ok if i insist on it? im really sorry. i just
dont like to use the option group in my current form.
 
A

Allen Browne

Suit yourself.

Probably better to use the AfterUpdate event of the buttons. (Just seems the
more logical choice.)

In any case, I don't think you will be able to solve the problems with the
code when the form has no records and no new records can be added. Access is
just too buggy and inconsitent in that case to do anything reliably.

For another example of that issue, see:
Incorrect display of data
at:
http://allenbrowne.com/bug-06.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
 
G

Guest

well, i guess i have to redo the form design then.

thank you sir allen browne. i think i know now why. i find your site very
useful. :D still reading your other stuffs though.
 
R

Rick Brandt

wendell said:
yeah, i have tried that already and it worked.

i really dont know but maybe it is just my preference to use toggle
over option group. would it be ok if i insist on it? im really
sorry. i just dont like to use the option group in my current form.

The frame of the option group can be made transparent so that all you see are
the ToggleButtons. Mutually exclusive choices should be represented in a single
table field though rather than a field per button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top