473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,387 developers and data experts.

Hide/Display SubMenu Buttons

Denburt
1,356 Expert 1GB
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 8729

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

Similar topics

1
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...
1
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...
5
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...
2
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 {...
7
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...
2
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. ...
18
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.