Toggle Buttons...Help Needed with coding!!...PLEASE!

hey yer barred

Board Regular
Joined
Jun 19, 2007
Messages
232
Hi All!

I have never used toggle buttons before so this is probaly why they aint working!

Just so I can get used to them, Ive created 3 simple toggle buttons called Call Centre, Team Manager and Agent.

Which ever one is active, and you click on a button called 'Test'...it will display a message box saying Call Centre.
e.g - if Team Manager is toggled, and test is clicked, Team Manager will appear in a message box..

Heres my coding

Dim togag As New Control
Dim togcc As New Control
Dim togtm As New Control

If Me.togag.Value = True Then
MsgBox "Agent"
ElseIf togcc.Value = True Then
MsgBox "Call Centre"
ElseIf togtm.Value = True Then
MsgBox "Team Manager"
Else
MsgBox "Nothing Selected!"
End If

End Sub


Any ideas why its not working?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

vranjit138

Board Regular
Joined
Dec 18, 2006
Messages
141
instead of declaring = True replace it with 1 and check for the result

Regards
Ranjit
 

VicRauch

Well-known Member
Joined
Mar 23, 2006
Messages
2,032
Call Centre, Team Manager and Agent
This is what you said you "called" each of the three toggle buttons. But in your code you "called" them "togag", "togcc", "togtm". Access has no idea what you are refering to in your code. You need to use the actual name you gave those 3 buttons on your form. The Dim statements you used in your code don't tell Access anything about the toggle buttons on your form.
And, by the way, True is the correct thing to use in this case. "1" is not True, "-1" is True.
 

hey yer barred

Board Regular
Joined
Jun 19, 2007
Messages
232
Also, togAc, togCC and togTM are the names of the toggle boxes on the form!
 

VicRauch

Well-known Member
Joined
Mar 23, 2006
Messages
2,032
Are these toggle buttons inside of an Option box?

Why have you done this:
Code:
Dim togag As New Control 
Dim togcc As New Control 
Dim togtm As New Control
I would think that if you take these three lines out, it would help. Also, I never use .Value when dealing with a control on a form.
 

hey yer barred

Board Regular
Joined
Jun 19, 2007
Messages
232
They are in a option box
Dim stuff i got of the net that didnt work!
 

VicRauch

Well-known Member
Joined
Mar 23, 2006
Messages
2,032
I'm really sorry, but I thought I had sent you yesterday the same stuff that is in this post, but I see it never got to the forum. :(
Toggle buttons work the same way as Option buttons and Check boxes when inside of an Option Box. So, what you will need to do is to use the Option Value property in each of the Toggle Buttons. Make togAc = 1, togCC = 2, and togTM = 3. Then in the code, you will need to reference the option box within the If/If Else/End If logic.
Code:
If Me.OptionBox = 1 Then 
  MsgBox "Agent" 
ElseIf Me.OptionBox = 2 Then 
  MsgBox "Call Centre" 
ElseIf Me.OptionBox = 3 Then 
  MsgBox "Team Manager" 
Else 
  MsgBox "Nothing Selected!" 
End If
 

Forum statistics

Threads
1,181,399
Messages
5,929,743
Members
436,687
Latest member
Glass of Gin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top