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 -
Option Compare Database
-
Option Explicit
-
-
Public myDetVal As Integer
-
Public XVal As Integer
-
Public myX As Integer
-
Public myY As Integer
-
-
Public Sub FocusYN(frm As Form, Optional strCtlName As String)
-
Dim ctl As Control
-
Dim GrpInt As Integer, i As Integer, cnt As Integer, myInt As Integer, inInt As Integer
-
Dim GrpNme() As Variant, GrpOrd() As Variant
-
Dim FndIt As Boolean
-
On Error GoTo FocusYNErr
-
If strCtlName <> "Detail" Then
-
If frm(strCtlName).Tag <> "" Then
-
GrpInt = Right(frm(strCtlName).Tag, 1)
-
frm(strCtlName).Value = 1
-
Else
-
frm(strCtlName).Value = 0
-
End If
-
frm(strCtlName).SetFocus
-
myDetVal = 0
-
Else
-
frm!Search.SetFocus
-
End If
-
-
ReDim Preserve GrpOrd(myInt)
-
For Each ctl In frm.Controls
-
If ctl.ControlType = 122 Then 'also known as ControlType acToggleButton
-
If strCtlName = "Detail" Then frm(ctl.Name).Value = 0
-
If GrpInt = Right(frm(ctl.Name).Tag, 1) And Left(frm(ctl.Name).Tag, 1) <> "V" Then
-
If ctl.Name <> strCtlName Then
-
inInt = InStr(frm(ctl.Name).Tag, ";")
-
If Left(frm(ctl.Name).Tag, inInt - 1) - 1 > myInt Then
-
myInt = Left(frm(ctl.Name).Tag, inInt - 1) - 1
-
ReDim Preserve GrpOrd(myInt)
-
End If
-
GrpOrd(Left(frm(ctl.Name).Tag, inInt - 1) - 1) = ctl.Name
-
End If
-
Else
-
If ctl.Name <> strCtlName And frm(ctl.Name).Value <> 0 Then
-
frm(ctl.Name).Value = 0
-
End If
-
If frm(ctl.Name).Tag <> "" And Not frm(ctl.Name).Tag Like "V*" Then
-
frm(ctl.Name).Visible = False
-
End If
-
End If
-
End If
-
Next
-
-
For i = 0 To UBound(GrpOrd)
-
Set ctl = frm(GrpOrd(i))
-
If ctl.ControlType = 122 And strCtlName <> "DETAIL" Then 'also known as ControlType acToggleButton
-
Select Case i
-
Case 0
-
ctl.Top = frm(strCtlName).Top
-
ctl.Left = frm(strCtlName).Left + frm(strCtlName).Width
-
Case 1 To 6
-
ctl.Top = frm(GrpOrd(i - 1)).Top + frm(GrpOrd(i - 1)).Height
-
ctl.Left = frm(strCtlName).Left + frm(strCtlName).Width
-
Case 7
-
ctl.Top = frm(strCtlName).Top
-
ctl.Left = ((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width)
-
Case 8 To 13
-
ctl.Top = frm(GrpOrd(i - 1)).Top + frm(GrpOrd(i - 1)).Height
-
ctl.Left = ((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width)
-
Case 14
-
ctl.Top = frm(strCtlName).Top
-
ctl.Left = (((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width) + frm(strCtlName).Width)
-
Case 15 To 20
-
ctl.Top = frm(GrpOrd(i - 1)).Top + frm(GrpOrd(i - 1)).Height
-
ctl.Left = (((frm(strCtlName).Left + frm(strCtlName).Width) + frm(strCtlName).Width) + frm(strCtlName).Width)
-
Case Else
-
MsgBox "Check your controls or your code there appears to be more buttons than 3 rows of 7 in each!"
-
End Select
-
frm(GrpOrd(i)).Visible = True
-
End If
-
SkipIt:
-
Next
-
Set ctl = Nothing
-
-
FocusYNExit:
-
Exit Sub
-
FocusYNErr:
-
If Err.Number = 2100 Then
-
MsgBox "Your form is too small to show all of the buttons!"
-
Exit Sub
-
ElseIf Err.Number <> 0 Then
-
MsgBox Err.Number & " " & Err.Description
-
End If
-
End Sub
-
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: -
Option Compare Database
-
Option Explicit
-
-
Private Sub Form_Load()
-
myDetVal = 0
-
XVal = 1
-
myX = 1
-
Detail_MouseMove 1, 0, 1, 1
-
End Sub
-
-
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
If myDetVal = 0 Then
-
If XVal = 0 Then
-
myX = X
-
myY = Y
-
XVal = 1
-
Else
-
If myY > 0 Then
-
If myY - Y > 100 Or myY - Y < -100 Then
-
FocusYN Me, "Detail"
-
myDetVal = 1
-
End If
-
End If
-
If myX > 0 Then
-
If myX - X > 100 Or myX - X < -100 Then
-
FocusYN Me, "Detail"
-
myDetVal = 1
-
End If
-
End If
-
End If
-
End If
-
End Sub
-
Private Sub Search_GotFocus()
-
Detail_MouseMove 1, 0, 1, 1
-
End Sub
-
-
Private Sub Search_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
Detail_MouseMove 1, 0, 1, 1
-
End Sub
-
Private Sub Toggle1_GotFocus()
-
If Me!Toggle1 = 0 Then
-
FocusYN Me, "Toggle1"
-
End If
-
End Sub
-
-
Private Sub Toggle1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
If Me!Toggle1 = 0 Then
-
Me!Toggle1.SetFocus
-
FocusYN Me, "Toggle1"
-
End If
-
End Sub
-
Private Sub Toggle3_GotFocus()
-
If Me!Toggle3 = 0 Then
-
FocusYN Me, "Toggle3"
-
End If
-
End Sub
-
-
Private Sub Toggle3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
If Me!Toggle3 = 0 Then
-
Me!Toggle3.SetFocus
-
FocusYN Me, "Toggle3"
-
End If
-
End Sub
-
0 8771 Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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>
|
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...
|
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;
}
|
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...
| |
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
|
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...
|
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>
...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
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...
| |