I currently have a tab control with 4 tabs. Each tab is tied to a checkbox, in which the tab will open when the checkbox clicks.
However, I am struggling with how to hide the entire tab control or tabs upon opening the form. Ergo, I only want the tabs to start appearing when boxes are ticked. Whereas right now, the tabs all appear when the forms open.
my current code is this:
Private Sub Type_C_Click()
If Me.Type_C = vbTrue Then
Me.Section_III__Cybersecurity.Visible = True
Else
Me.Section_III__Cybersecurity.Visible = False
End If
End Sub
Private Sub Type_D_Click()
If Me.Type_D = vbTrue Then
Me.Section_IV__Data_Security.Visible = True
Else
Me.Section_IV__Data_Security.Visible = False
End If
End Sub
Private Sub Type_I_Click()
If Me.Type_I = vbTrue Then
Me.Section_V__ICT_Outage.Visible = True
Else
Me.Section_V__ICT_Outage.Visible = False
End If
End Sub
Private Sub Type_G_Click()
If Me.Type_G = vbTrue Then
Me.Section_VI__Loss_of_Government_Issue_Equipment.Visible = True
Else
Me.Section_VI__Loss_of_Government_Issue_Equipment.Visible = False
End If
End Sub
I've tried to use form current and hide the visibility of the tab control, however, subsequently none of the tabs will appear when the boxes are ticked. Similarly, I've tried to hide individual tabs in form current, however i get error 2156 where one of the tabs is the focus and I can't seem to bypass it.
Any help would be greatly appreciated!
Make sure checkbox TripleState property is set to no. Set each Tab page Visible property to no in form design.
Before setting page to not visible, set focus to some other control on form that is not located on any of the pages because page that has focus cannot be set not visible. Conversely, after setting a page visible, put focus on a control located on that page.
Related
Currently implementing toggle buttons that controls the visibility of tabs in a subform. When opening the subform on its own, the toggle buttons work, however when I am on the main form, the toggle buttons don't work anymore.
Private Sub Toggle53_Click()
If Me.Toggle53.Value = True Then
Me.IDD.Visible = True
Me.IDS.Visible = True
Else
Me.IDD.Visible = False
Me.IDS.Visible = False
End If
I also tried implementing this code in
Private Sub Form_Current()
for the subform's current event, but it doesn't work either.
Any help is appreciated thanks!
Don't know the structure of your forms, but to hide a tab using a toggle button, you need to reference the tab by index as shown below. Obviously, if the tab control is located in a subform control, you will need to change the reference to it.
Private Sub Toggle1_Click()
TabCtl.Pages(0).Visible = Toggle1.Value
End Sub
If the tab control is located in a subform control:
Private Sub Toggle1_Click()
SubformControl.Form.TabCtl.Pages(0).Visible = Toggle1.Value
End Sub
If all the forms are on the page you could add condittional If on them with booleans to show them, so on toggle click just set everyones boolean to false except the item you want to be visible.
For example create boolean called IDDbool=false, bind it to the subform and change it on click to true to show it.
Also option is to create method on the sub form that controls the tabs and call in that method from the main one.
In my subform (VBA in ms-access) there is a button called "Test" and this button has to be set invisible after it was clicked.
So I tried:
Private Sub Test_Click()
'Do some stuff
Me.Test.Visible = False
End Sub
But this does not work. It raises an error because it is not possible to make a button invisible, which has the focus. Unfortunately the button is the only button on the form (the other controls are lables). As the button is in a subform, I tried to set the focus to a button in the parent:
Private Sub Test_Click()
'Do some stuff
call me.parent.schclose.SetFocus
Me.Test.Visible = False
End Sub
But this did not work either. 'call me.parent.schclose.SetFocus' does not raise an error but 'Me.Test.Visible = False' does like before.
So, how to make the button invisible?
What you can do is expand your user form and add a button that is visible by default. Let's say currently your user form has height of 300 and a width of 300. Expand the form to be 500X500 and place the new button on the bottom right of that form (keep the visible property set to Yes). Next add this code to the form:
Private Sub UserForm_Initialize()
Me.Height = 300
Me.Width = 300
End Sub
Now when you click on your test button it will be invisible and the new button will still be hidden because it's not within the height you set above.
Inspired by the answer of VBA_SQL_Programmer I created a empty read-only edit field with a transperent boarder (which means it is basicly invisible) in my form to set the focus to.
So my code looks like this:
Private Sub Test_Click()
'Do some stuff
call me.invisibleTextBox.SetFocus
Me.Test.Visible = False
End Sub
This works without manipulating the size of the form.
But there is a problem too, because as the focus is set to the textBox, the user can see a blinking cursor.
I am using a form with two combo-boxes and a button. I want button to be disabled initially and it should enable only when the user selects a valid value in both the combo-boxes.
I tried to disable the button using the form initialize sub-routine but the button appears to be active. What can be the issue? Also how to enable the button using if conditions?
Private Sub UserForm1_Initialize()
Me.Shapes("ButtonName1").ControlFormat.Enabled = False
ActiveSheet.Shapes("ButtonName1").Font.ColorIndex = 16
End Sub
You made a couple of mistakes in your code.
UserForm1_Initialize should be UserForm_Initialize
You can use Userform.ButtonName1 to access the properties of your button
Use TextFrame.Characters.Font.ColorIndex to access the text on a button on the worksheet
The code below should work
Private Sub UserForm_Initialize()
UserForm1.ButtonName1.Enabled = False
ActiveSheet.Shapes("ButtonName1").TextFrame.Characters.Font.ColorIndex = 16
End Sub
I have a command button in excel that will open the userform
Sub openfile ()
UserForms1.Show
End Sub
Now, how do I hide the command button on first page of the form then unhide it when the next page is selected?
Place the following into your UserForm_Initialize....
Me.CommandButton1.Visible = False. Alternatively you can set the visible value of the button to false in properties window!
Then add this to the code for your UserForm
Private Sub MultiPage1_Change()
If MultiPage1.Value = 1 Then 'page values start with 0 as the first page
Me.CommandButton1.Visible = True
Else
Me.CommandButton1.Visible = False
End If
End Sub
Currently using vba with excel 2007...
I am currently testing the capabilities of functions and am a little stuck using buttons. I have two buttons, named ONE and TWO. Pressing either calls up a function Calc with each button passing the variable of the others name. As follows:
Private Sub ONE_Click()
Calc TWO
End Sub
Private Sub TWO_Click()
Calc ONE
End Sub
Function Calc(B As CommandButton)
B.Enabled = False
End Function
My understanding is that pressing button ONE passes the variable TWO to the Function Calc, and then disables button TWO.
I also have a button labeled Reset which serves as follows:
Private Sub Reset_Click()
ONE.Enabled = True
TWO.Enabled = True
End Sub
The results of this, if I press button ONE, button TWO greys out and appears "disabled". However when I hit the reset button, it stays grey. Investigating the properties of the button reveals that it doesn't actually get disabled. I installed another button that directly disables button two, i.e. TWO.Enabled = False, instead of using a variable to do so.
When the button is directly disabled using the direct button, resetting enables the button as it should, and the properties reflect that the button is disabled.
Would anyone know why using a variable to disable a button like this results in an illusionary disabling?
And better yet, how to overcome the issue?
If you have trouble calling through an indirrect reference, then use a static parameter.
Private Sub ONE_Click()
Calc "TWO"
End Sub
Private Sub TWO_Click()
Calc "ONE"
End Sub
Now you can use that parameter to act on the object.
Function Calc(B As String)
If B = "ONE" Then
ONE.Enabled = False
ElseIf B = "TWO" Then
TWO.Enabled = False
Else
Exit Function
End If
End Function