473,778 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide/Display SubMenu Buttons

Denburt
1,356 Recognized Expert Top Contributor
This code is for a Toggle Button layout on a form, with this code you can set a number of toggle buttons visible and have multiple submenus that will stay hidden when not in use. My main menu is set up with this code and the way I set it up the first button is my search toggle button no submenu (this prevents a submenu from displaying when the form is first opened) TabIndex set to 0 (I like using the keyboard) the second toggle button is called Forms, the forms toggle button has submenu buttons for the forms I want displayed. The TabIndex can be a bit mundane at times trying to keep things in order but the nice thing is that in Design view of this form you can put the buttons any where you want and they will position themselves when they are called. I like having the tab index structured like so, the search button would be 0 Forms button would be 1 the first submenu button would be 2 the next submenu = 3 continue until all submenu buttons have their index then back to the menus next main button.

I placed the following in a module I keep for a majority of my form code. You may want to rename the bold statement to your TabIndex=0 control

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public myDetVal As Integer
  5. Public XVal As Integer
  6. Public myX As Integer
  7. Public myY As Integer
  8.  
  9. Public Sub FocusYN(frm As Form, Optional strCtlName As String)
  10. Dim ctl As Control
  11. Dim GrpInt As Integer, i As Integer, cnt As Integer, myInt As Integer, inInt As Integer
  12. Dim GrpNme() As Variant, GrpOrd() As Variant
  13. Dim FndIt As Boolean
  14. On Error GoTo FocusYNErr
  15. If strCtlName <> "Detail" Then
  16.     If frm(strCtlName).Tag <> "" Then
  17.         GrpInt = Right(frm(strCtlName).Tag, 1)
  18.         frm(strCtlName).Value = 1
  19.     Else
  20.         frm(strCtlName).Value = 0
  21.     End If
  22.     frm(strCtlName).SetFocus
  23.     myDetVal = 0
  24. Else
  25.     frm!Search.SetFocus
  26. End If
  27.  
  28. ReDim Preserve GrpOrd(myInt)
  29. For Each ctl In frm.Controls
  30.     If ctl.ControlType = 122 Then 'also known as ControlType acToggleButton
  31.         If strCtlName = "Detail" Then frm(ctl.Name).Value = 0
  32.         If GrpInt = Right(frm(ctl.Name).Tag, 1) And Left(frm(ctl.Name).Tag, 1) <> "V" Then
  33.             If ctl.Name <> strCtlName Then
  34.                 inInt = InStr(frm(ctl.Name).Tag, ";")
  35.                 If Left(frm(ctl.Name).Tag, inInt - 1) - 1 > myInt Then
  36.                     myInt = Left(frm(ctl.Name).Tag, inInt - 1) - 1
  37.                     ReDim Preserve GrpOrd(myInt)
  38.                 End If
  39.                 GrpOrd(Left(frm(ctl.Name).Tag, inInt - 1) - 1) = ctl.Name
  40.             End If
  41.         Else
  42.             If ctl.Name <> strCtlName And frm(ctl.Name).Value <> 0 Then
  43.                 frm(ctl.Name).Value = 0
  44.             End If
  45.             If frm(ctl.Name).Tag <> "" And Not frm(ctl.Name).Tag Like "V*" Then
  46.                 frm(ctl.Name).Visible = False
  47.             End If
  48.         End If
  49.     End If
  50. Next
  51.  
  52. For i = 0 To UBound(GrpOrd)
  53.     Set ctl = frm(GrpOrd(i))
  54.     If ctl.ControlType = 122 And strCtlName <> "DETAIL" Then 'also known as ControlType acToggleButton
  55.      Select Case i
  56.         Case 0
  57.             ctl.Top = frm(strCtlName).Top
  58.             ctl.Left = frm(strCtlName).Left + frm(strCtlName).Width
  59.         Case 1 To 6
  60.             ctl.Top = frm(GrpOrd(i - 1)).Top + frm(GrpOrd(i - 1)).Height
  61.             ctl.Left = frm(strCtlName).Left + frm(strCtlName).Width
  62.         Case 7
  63.             ctl.Top = frm(strCtlName).Top
  64.             ctl.Left = ((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width)
  65.         Case 8 To 13
  66.             ctl.Top = frm(GrpOrd(i - 1)).Top + frm(GrpOrd(i - 1)).Height
  67.             ctl.Left = ((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width)
  68.         Case 14
  69.             ctl.Top = frm(strCtlName).Top
  70.             ctl.Left = (((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width) + frm(strCtlName).Width)
  71.         Case 15 To 20
  72.             ctl.Top = frm(GrpOrd(i - 1)).Top + frm(GrpOrd(i - 1)).Height
  73.             ctl.Left = (((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width) + frm(strCtlName).Width)
  74.         Case Else
  75.             MsgBox "Check your controls or your code there appears to be more buttons than 3 rows of 7 in each!"
  76.     End Select
  77.     frm(GrpOrd(i)).Visible = True
  78.     End If
  79. SkipIt:
  80. Next
  81. Set ctl = Nothing
  82.  
  83. FocusYNExit:
  84. Exit Sub
  85. FocusYNErr:
  86. If Err.Number = 2100 Then
  87.     MsgBox "Your form is too small to show all of the buttons!"
  88.     Exit Sub
  89. ElseIf Err.Number <> 0 Then
  90.     MsgBox Err.Number & "   " & Err.Description
  91. End If
  92. End Sub
  93.  

To Effectively show & hide the buttons you will need to place a value in the tag properties of the main button that will control the buttons to be shown or hidden. For Example 1 main button on my menu form is called "Forms" it has a tag property = VGrp1 (V for always visible and I used the letters Grp to relay which group it belongs too). The submenu buttons of this Forms button should have a tag property starting with a number for the order you want them displayed starting at the top working your way down then to the right and separated by a semi colon they should be numbered starting with 1 in the order that you want them listed such as the “Add Invoice” button has a tag property = 1;Grp1 the next button following below has a tag property = 2;Grp1 (Button 2 of the same group)! The Menu next main button would have a tag of VGpr2 and the submenu buttons would be tagged with 1;Grp2,2;Grp2 etc. up to 21 buttons 3 rows of 7.

Now for the rest of the code in the forms module:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5. myDetVal = 0
  6. XVal = 1
  7. myX = 1
  8. Detail_MouseMove 1, 0, 1, 1
  9. End Sub
  10.  
  11. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  12. If myDetVal = 0 Then
  13.     If XVal = 0 Then
  14.         myX = X
  15.         myY = Y
  16.         XVal = 1
  17.     Else
  18.         If myY > 0 Then
  19.             If myY - Y > 100 Or myY - Y < -100 Then
  20.                 FocusYN Me, "Detail"
  21.                 myDetVal = 1
  22.             End If
  23.         End If
  24.         If myX > 0 Then
  25.             If myX - X > 100 Or myX - X < -100 Then
  26.                 FocusYN Me, "Detail"
  27.                 myDetVal = 1
  28.             End If
  29.         End If
  30.     End If
  31. End If
  32. End Sub
  33. Private Sub Search_GotFocus()
  34.     Detail_MouseMove 1, 0, 1, 1
  35. End Sub
  36.  
  37. Private Sub Search_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  38. Detail_MouseMove 1, 0, 1, 1
  39. End Sub
  40. Private Sub Toggle1_GotFocus()
  41.     If Me!Toggle1 = 0 Then
  42.         FocusYN Me, "Toggle1"
  43.     End If
  44. End Sub
  45.  
  46. Private Sub Toggle1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  47. If Me!Toggle1 = 0 Then
  48.     Me!Toggle1.SetFocus
  49.     FocusYN Me, "Toggle1"
  50. End If
  51. End Sub
  52. Private Sub Toggle3_GotFocus()
  53.     If Me!Toggle3 = 0 Then
  54.         FocusYN Me, "Toggle3"
  55.     End If
  56. End Sub
  57.  
  58. Private Sub Toggle3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  59. If Me!Toggle3 = 0 Then
  60.     Me!Toggle3.SetFocus
  61.     FocusYN Me, "Toggle3"
  62. End If
  63. End Sub
  64.  
Mar 23 '07 #1
0 8771

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2115
by: Benoit | last post by:
Here is a quick view of what my program is doing: I am using a system hook to add a menu inside the system menu of my Internet Explorer. Everything seems to work fine for now , my submenu is there, i can click it ,it works , everything is OK except one thing: The problem: When you select the option to "Group similar taskbar button" together
1
11947
by: Don Grover | last post by:
I have a table thats wrapped in a div tag, that when user selects 1 of 2 radio buttons it hides or shows table, this works ok. But I want to set the table show hide on what the existing state of radio buttons are on page load aswell, so if one button is allready selected then the table is hidden else it is shown, can some help me with this, Existing code below Regards Don. '**************** <html>
5
2181
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the shown method is called, the table gets skewed and the presentation of the data on the page goes horribly wrong. I don't think this is a table issue as I have spent alot of time staring at this code. Here is the html...
2
12190
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow { display: none; }
7
29154
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field below the comment with a spell check & submit button. Clicking "Amend" would display the same buttons & text field but pre-populated with the original comment. Using Java Script how do I show / hide the text field in my list of comments but have...
2
1584
by: Poornima | last post by:
Hello I have a html page with 2 layers,one for the main menu and the other for the submenu.The submenu should be displayed on hovering on the main menu is displayed else it should be hidden. How can i get the above requirement using javascripts can u plz give me the javascript code
18
7570
by: Liquidtouch | last post by:
I have been searching on this for awhile and cant find anything and playing around with it got me no where. I will start with what I am after and then explain what I have. I have a table with 3 rows and 2 columns. I would like on page load to only have one row visible with the bottom two rows hidden. I would like to have an "add" button on the bottom most visible row. When you click the "add" button it adds a row to the bottom and moves the...
0
3577
by: rehanmomin | last post by:
Just to start off, I am writing a web application using C#. I have a Menu which is binded to an XML datasource. There are three menu items each with submenus and a textbox where I want to display the value of the selected menu item. Heres the XML datasource that I am using: <?xml version="1.0" encoding="utf-8" ?> <Home> <Menu text="Patient" description=" "> <SubMenu text="First Name" description="firstName"></SubMenu> ...
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9470
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10127
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.