Resize a control inside a Ribbon Panel - ribbon

I have a form with a ribbon bar and I want the controls that are on the RibbonPanel to resize with the rest of the form. The docked RibbonControl resizes fine and the RibbonPanel resizes with it but the controls that Docked/Anchored on the RibbonPanel do not resize.
How do you get controls on a ribbon panel to Dock or Anchor correctly?

For a work around I placed a normal Panel control inside of the RibbonPanel control, and docked all the controls I want to resize in that panel. Using a simple resize method and a couple event handlers to dynamically resize that panel, the controls now Anchor and Dock normally while on a RibbonPanel.
Private Sub Form1_Resize(sender As System.Object, e As System.EventArgs) Handles MyBase.Resize
Resize()
End Sub
Private Sub RibbonControl1_SelectedRibbonTabChanged(sender As System.Object, e As System.EventArgs) Handles RibbonControl1.SelectedRibbonTabChanged
Resize()
End Sub
Private Sub Resize()
Select Case RibbonControl1.SelectedRibbonTabItem.Name
Case "RibbonTabItem1"
Panel1.Size = RibbonPanel1.Size
Case "RibbonTabItem2"
Panel2.Size = RibbonPanel2.Size
Case ...
End Select
End Sub

Related

Microsoft Access how to stop scrolled text field from returning to top (like scroll-to-top) upon losing focus

I'm using Access 2016 in Win 10, everything updated and current. I have a form with a standard Access TextBox with a vertical scrollbar. All is fine unless I scroll down then click off the field to read info from another source or whatever because the scrolled text rolls right back to the top and I have to scroll back down to where I was before I can resume work. It wastes time and derails my train of thought.
I see no property or method to lock the 'caret' or otherwise disable this annoying behavior. I have also researched everywhere I can think of and no one seems to know what to do about it.
I've even built my own scroll buttons which worked great except it got complicated trying to keep track of the text position if I added or deleted text. So, if someone has a good custom scrollbar in VBA/VB6 I'd love to see it, please.
Thanks for your time and advice. I appreciate it.
Kent in KC.
Set and restore the selected position:
Option Compare Database
Option Explicit
Private LastPosition As Long
Private Sub YourTextbox_LostFocus()
LastPosition = Me!YourTextbox.SelStart
End Sub
Private Sub YourTextbox_GotFocus()
Me!YourTextbox.SelStart = LastPosition
Me!YourTextbox.SelLength = 0
End Sub
Private Sub Form_Current()
' Reset last position.
LastPosition = 0
End Sub
It will scroll the textbox to make the line when left to the top line visible.

Is the MS-Access Navigation Pane visible?

The following code to close the Access Navigation Pane works.
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
But the problem is that if the Navigation Pane is already closed then the acCmdWindowHide will just hide any other object (i.e. form, table) which was open.
I use DoCmd.TransferDatabase in my code and when this is executed the Navigation Pane is sometimes opened. This may happen if a warning message about data import appears and the user clicks cancel. To be sure the user does not see the pane I want to hide it but if it is already hidden then there is nothing to hide but the above command just hides my form and that is not what I want.
The line
DoCmd.NavigateTo "acNavigationCategoryObjectType"
is always executed and does not return anything. It does not return an error if there is no Navigation Pane to navigate to.
My question is: How can I determine if the Navigation Pane is currently open so that I know I have to close it.
Or how can I make sure that I close the Navigation Pane but no other object if I use the above code?
How can I determine if the Navigation Pane is currently open so that
I know I have to close it. Or how can I make sure that I close the
Navigation Pane but no other object if I use the above code?
By holding the Application.CurrentObjectName value before setting focus to the Nav Pane,
and then comparing that value to Application.CurrentObjectName after DoCmd.NavigateTo ("acNavigationCategoryObjectType"), you can tell if the Nav Pane can be closed.
I found that the code suggested in other examples would fail if a search filter was currently set in the navigation pane. In some cases this would cause the active form to close. That can lead to a bad user experience. This routine should get around that. I have only found two limitations:
The Nav Pane is open but no other objects are open. I can't think of a good reason why you'd be hiding the Nav Pane in this instance.
You open tblEmployee from the Nav Pane and it becomes the active object, then you run this routine to hide the Nav Pane. It won't do anything because tblEmployee is the active object name and it is also the selected item in the Nav Pane. I don't think you'll run into this situation much but YMMV.
In either of those cases the sub will not hide the navigation pane which is better than close the active form.
Public Sub HideNavPane()
' This will hide the Navigation Pane.
' It works even if a search filter is set, unlike other solutions that may
' inadvertently close the active object.
' Limitations: An object (form, report, query, etc) must be open and it
' cannot be the same name as the selected item in the nav pane
' or this will do nothing.
Dim strCurrentObjectName As String
strCurrentObjectName = Application.CurrentObjectName
' Move focus to the navigation pane/database container
DoCmd.NavigateTo ("acNavigationCategoryObjectType")
If strCurrentObjectName <> Application.CurrentObjectName Then
' The Navigation Pane is open and has focus.
' Use the window menu to hide the navigation pane
DoCmd.RunCommand acCmdWindowHide
End If
End Sub
This forum thread suggests:
Public Function HideIt()
' Employee is just any existing table
DoCmd.SelectObject acTable, "Employee", True
If Application.CurrentObjectName = "Employee" Then DoCmd.RunCommand acCmdWindowHide
End Function

fitting forms to various screen settings in ms access 2010

I have a set of two nested navigation subforms in an ms access 2010 database. The problem is that, when different users on different machines view the database through different screen resolutions and text size settings, the forms can have silly wastes of screen real estate, such as in the following image:
How do I set the width and height of each navigation subform so that each of the two navigation subforms has a small inset (30 pixels?) at the right and bottom, assuming that the left and top are fixed?
Here is the code that I worked up so far, but it pushes things too far to the right and to the bottom, without leaving the insets that I need at the right and bottom:
Main form (this is the outermost form):
Private Sub Form_Resize()
On Error Resume Next
Me.NavigationSubform.Width = Me.WindowWidth - (Me.NavigationSubform.Left + 10)
Me.NavigationSubform.Height = Me.WindowHeight - (Me.NavigationSubform.Top + 10)
End Sub
FindClientsNavigation form (this is the second level form):
Private Sub Form_Resize()
On Error Resume Next
Me.NavigationSubform.Width = Me.WindowWidth - (Me.NavigationSubform.Left + 10)
Me.NavigationSubform.Height = Me.WindowHeight - (Me.NavigationSubform.Top + 10)
End Sub
I uploaded a simplified version of the database with enough to recreate the problem at this file sharing site.
If you want to recreate the problem on your pc after downloading the database, you can set the windows text size property using the following dialog in the control panel:
Instead of messing about with code, set the HorizontalAnchor and VerticalAnchor properties of the subform controls appropriately at designtime, i.e. to Both. The default is for the horizontal anchor to be left only and the vertical anchor to be top only; setting to left-and-right and top-and-bottom will mean the control stretches accordingly when its parent resizes.
There is simple navigation available in ribbon. See the picture above.

FormFooter Visible property - Proportion form height accordingly

When trying to toggle the FormFooter's visible property, how do you ensure that when the footer is switched to visible=Yes that it grows out the bottom of the form rather than growing in to the Detail section of the form?
I've tried setting CanGrow properties of all sections to yes. I've even tried to update the height property of the Details section to the additional proportion taken up by the height of the footer section when it is visible. Neither of these work and there doesn't seem to be an overall form height property that I can adjust via VBA.
I'm looking to hide a section of controls in a pop-up form that are only revealed when the user clicks a button. Was hoping to do this in the foot section and then simply use the command button to toggle the FormFooter's visible property, but can't seem to do this without it either encroaching on the Detail section or adding a scroll bar to the Detail section.
I think you want to avoid cannibalizing the form's Detail area when you make the FormFooter visible. The only way I know to do that is to increase the form's WindowHeight by the amount (FormFooter.Height) needed to accommodate the footer.
However, the WindowHeight property is read-only, so you can't change it directly. Instead, you can use the form's Move method to resize the form. Resizing the form indirectly changes the WindowHeight property value.
This VBA procedure did what I think you want when tested in Access 2007. And it did that for my pop-up form without causing any noticeable display flicker, which was a pleasant surprise.
Private Sub cmdToggleFooter_Click()
Dim lngWindowHeight As Long
If Me.FormFooter.Visible = True Then
' reduce WindowHeight by FormFooter.Height
lngWindowHeight = Me.WindowHeight - Me.FormFooter.Height
Else
' increase WindowHeight by FormFooter.Height
lngWindowHeight = Me.WindowHeight + Me.FormFooter.Height
End If
' adjust form's window size
Me.Move Left:=Me.WindowLeft, Height:=lngWindowHeight
' toggle FormFooter.Visible
Me.FormFooter.Visible = Not Me.FormFooter.Visible
End Sub
Have the footer visible at design time, so that it is visible (very briefly, at worst) when the form is being loaded. Then put a FormFooter.Visible=false in the Form Load.

changing "Tab Control" color

How can I change the background color of a Tab Control. I changed the forms color, but the tabs stay the same.
Thanks.
Check the Back Style of the Tab Control. If it's Normal. you'll get a gray background (with normal Windows settings). If it's Transparent then it will inherit the background colour of the form.
If you want it to be an entirely different colour, you might have to add a rectangle to the form (make the background non-transparent), maximise it within the tab and then set the colour of the rectangle.
As for the tabs them selves, I don't see a way of setting their colour independently.
As far as I know, in Access 2000/2002/2003 it's impossible to change neither background, not foreground colors of the tabs.
So, if you want to change the appearance of entire tab control, I think you are out of luck.
However, if your real goal is to implement some sort of color-coding of a tab control's pages, here is what I did when I had this problem:
I placed a colored rectangle on each page of the tab control to provide different background colors for different pages.
As for tabs themselves. Fortunately they can contain images, so I created trivial image files, each of which was a small colored bullet (square, rectangle, circle - whatever looks nicer to you) and placed them on tabs, next to text labels.
Thus, the entire control still remained grey (or whatever is the current "button color" in the Windows's current theme), but each tab and each page got associated with whatever colors I needed them to have.
With Access 2010, setting the color of the "Pressed Color" property in a tab control object allows you to set the background color of a tab page.
With Access 2013, also setting the color of the "Back Color" property for the tab control (to the same color as the "Pressed Color") was necessary.
CodeSlave made the very good suggestion:
If you want it to be an entirely
different colour, you might have to
add a rectangle to the form (make the
background non-transparent), maximise
it within the tab and then set the
colour of the rectangle.
If you want to have a background that is larger in relation to the tab dimensions than the tab allows (there is a hard border that can't be exceeded), there is another solution (though it's somewhat more complicated -- which is what usually happens when you are tweaking appearance to not work the way your default environment is designed to work).
Set the tab control to transparent. Behind the tab, place a non-transparent box. Then in the OnChange event of the tab, change the background color of the box behind the tab.
Kinda messy, yes, but it allows you to have a background that is as large as the whole tab (or larger still, in the event that you might want items off the tab inside the same color field).
You can mock this up with a little code. Set the the Style property to None for the tab control and the use any other control that has a click event to create your own colourful tabs (you can even have images). Your code can either change tabs, or change the contents of a subform.
Change tab:
Me.NameOfTabControlPage.SetFocus
Change subform control contents:
Me.NameOfSubformControl.SourceObject = "NameOfSuitableForm"
I have developed a subroutine to set the small rectangle at the right of the tabs to transparent. I tested it with Access 2003 and 2007.
Private Const GWL_EXSTYLE = -20
Private Const WS_EX_TRANSPARENT = &H20&
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Sub PatchTabControl(ByVal f As Form)
Dim hwnd As Long
hwnd = FindWindowEx(f.hwnd, 0, "OFormSub", vbNullString)
If hwnd = 0 Then Exit Sub
hwnd = FindWindowEx(f.hwnd, hwnd, "OFormSub", vbNullString)
If hwnd = 0 Then Exit Sub
hwnd = FindWindowEx(hwnd, 0, "OTabControl", vbNullString)
If hwnd = 0 Then Exit Sub
SetWindowLong hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) Or WS_EX_TRANSPARENT
End Sub
Extending Duane Rochelle's helpful answer for Access 2010:
The problem seems to be that the names that Microsoft has given the properties that control the tab colours are contra-intuitive.
Basically, the color of the tabs can be controlled using the Pressed Color property. Look for it in the properties of the entire tab object, not the properties of individual tabs.
This means, setting Pressed Color to - for example - some kind of blue (say, #8EA3BD) makes all tabs blue. Since "pressed" means actually "the tab area is on top of the other tabs", this is more or less equivalent to colouring the tab area.
(For me personally, "Pressed Color" is a misleading name. Of all tabs in a tab object, one is visible by default, even without anybody having "pressed" a tab. A better name would be "Background color of visible tab".)
For the other elements of a tab object that one would like to paint:
For the colour of the text on the tab head (where you click to select the tab), use the Pressed Fore Color property.
For the background colour of tabs that are not visible (or "hidden behind the currently open tab"), use the Back Color property.
For text on the heads of hidden tabs, use the Fore Color property.
Accordingly, I would find the following names more intuitive:
Background color of visible tab (now "Pressed Color")
Text color of visible tab (now "Pressed Fore Color")
Background color of hidden tab (now "Back Color")
Text color of hidden tab (now "Fore Color")