Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle Button Control access 3 or more subforms?

Status
Not open for further replies.

webvine

Technical User
Oct 21, 2002
20
Hello,
I have 3 subforms that I would like to access using a Toggle Button Control, I can get it to work with 2 subforms - clicking the toggle button it will display 2 subforms going back and forth between the two, but I really would like to use this toggle button to display 3 subforms. I have played around with the code and I can manage to get it to display the 3 subforms going through a cycle once, but then I cannot click the toggle button anymore to re-pick a subform. Below is the code that I have so far...any suggestions? Thanks in advance.

Private Sub ToggleSubform_Click()
If Me![ToggleSubform].Caption = "&View Cracks Count" Then
Me![subfrmCount Windows].Visible = False
Me![subfrmCount Stains].Visible = False
Me![subfrmCount Cracks].Visible = True
Me![ToggleSubform].Caption = "&View Windows Count"
Me![ToggleSubform].Caption = "&View Stains Count"
Else
Me![subfrmCount Cracks].Visible = False
Me![subfrmCount Stains].Visible = True
Me![ToggleSubform].Caption = "&View Stains Count"
Me![ToggleSubform].Caption = "&View Windows Count"
End If
End Sub
 
At the end of each section of the if then you need to add this to it:

ToggleSubform = Null

This will allow the toggle group to reset the buttons.

If I take a peek in your Windows, to fix a problem, does that make me a "Peeping Tom"? Hmmmmmmmmmmv [pc1][shocked]
 
At the end of each section of the if then you need to add this to it:

ToggleSubform = Null

Another way to do it is to put a group of three buttons on the form, thus having one for each subform.

If I take a peek in your Windows, to fix a problem, does that make me a "Peeping Tom"? Hmmmmmmmmmmv [pc1][shocked]
 
Would I have put ToggleSubform = Null piece of code underneath the line Me![ToggleSubform].Caption = "&View Stains Count"? I tried and it pops up a Run-time error '438' Object doesn't support this property or method.

I have thought of putting 3 separate buttons on there as well but I really like the look and feel of 1 toggle button. Any other suggestions?
 
Then for that you would have to install a counter to count the click events for the toggle button.

Something like:

dim ClickCount = 0 'must be declared in the option explicit part of the code


'This will be in the click button event procedure
ClickCount = ClickCount + 1

Select Case ClickCount
Case 1
'Code for your first subform here followed by:'
Me![ToggleButtonName].value = 0
Case 2
'Code for your second subform here followed by:'
Me![ToggleButtonName].value = 0
Case 3
'Code for your third subform here followed by:'
Me![ToggleButtonName].value = 0
ClickCount = 0
End Select

Now that should do it for one toggle and my apologies for the null thing a toggle's value should be reset to zero.

If I take a peek in your Windows, to fix a problem, does that make me a "Peeping Tom"? Hmmmmmmmmmmv [pc1][shocked]
 
Excuse my limited programming experience but I'm not clear on how to implement your recommendation above into the existing ToggleSubform code. Do I merge these 2 pieces of code together or is your ClickCount code a whole new piece of code?
 
Anything below the "dim" statement goes into the On click event of the toggle button. What this code does is with the dim statement creates a public variable(ClickCount) to hold the number of times the on click event has taken place. It has to be a public variable or else the number would get reset to 0 with every click.

The ClickCount = ClickCount + 1 line of code just adds 1 to its self every time the on click is run

The Select Case ClickCount checks the value of ClickCount and then switches to the subform per your request(once you put the code into the green area where it says put the code).

The Me![ToggleButtonName].value = 0 clause just sets the toggle button back to its raised position getting ready for another click. (Acts like a command button if you ask me)

I do want to make a small change in the code since I was doing this on the fly I forgot that the first subform should already be present on the form. So first click would open second form, second click third form, so on and so forth.

Select Case ClickCount
Case 1
'Code for your second subform here followed by:'
Me![ToggleButtonName].value = 0
Case 2
'Code for your third subform here followed by:'
Me![ToggleButtonName].value = 0
Case 3
'Code for your first subform here followed by:'
Me![ToggleButtonName].value = 0
ClickCount = 0
End Select


If I take a peek in your Windows, to fix a problem, does that make me a "Peeping Tom"? Hmmmmmmmmmmv [pc1][shocked]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top