Is the MS-Access Navigation Pane visible? - ms-access

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

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.

MS-Access 2010: Mouse events "dead" in main form

MS-Access 2010:
Main form with item names and subform with item actions (date of action, etc.).
Purpose = quick consulting data using only the mouse, without any editing.
Idea: to switch to subform and back to mainform just by moving the mouse.
This works perfectly from the mainform to the subform (code in subform):
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Forms![MyMainForm]![MySubForm].SetFocus
End Sub
I tried to use the analogous procedure for back from the subform to the mainform. However, once the mouse has been over the subform, moving the mouse over the mainform or over a mainform's field, or even clicking on the mainform's background does not trigger the desired mouse actions (checked by inserting Stop into the corresponding code). By the way, clicking on the mainform's background with focus on the mainform triggers the mouse action, but .SetFocus leads to an error (no allowed action there).
Hence, the only way to set the focus back to the main form seems to be clicking into a field on the main form. But this is not self-evident for the users.
What I needed was to set the focus on the main form by moving the mouse. Of course, FIRST the focus MUST be set onto the main form, only thereafter one can focus on any field on the main form. The problem was that neither the main form itself nor its background do trigger mouse actions able to perform the action .SetFocus once the focus is on the subform.
However, I designed a work-around which works: over the whole form width at the bottom of the main form, I created a large, transparent, unbound Dummy field, which the mouse automatically crosses when it leaves the subform. Following code is in the main form's module:
Private Sub Dummy_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.SetFocus
Me![Empty].SetFocus
End Sub
Empty is a very small unbound field in a corner, to which the focus is set in a second step, where the cursor blinks to indicate the main form has focus.
It works ! Just the Dummy field must be big enough otherwise the mouse's crossing time is too short to trigger the desired action; this limitates the possibilities of design for the main form.

Access Vertical Scrollbar focus on top of the form

Any ideas on how to keep the scrollbar/focus on the top of a form?
I have continous form with many textboxes and listboxes that make the user scroll down the form no matter the resolution size of their screen. Ever since I implemented a Listbox with a rowsource query that will vary on the record, every time I change records the vertical scrollbar of the form will change focus to the bottom of the form.
I tried changing focus to controls on the top of the page or changing ways to change the rowsource of said listbox (using vba code like listbox.RowSource = theSQLQUERY or making the rowsource of the listbox with the sqlQuery). It used to work before I implemented that sourcecode, it had a sourcecode before and the problem never happened.
The rowsource query looks like this :
where active_flag = 0
My question is, How can I keep the vertical scrollbar/focus on the top of a form taking into account the listbox that changes rowsource?
The key is:
Ever since I implemented a Listbox with a rowsource query that will vary on the record, every time I change records the vertical scrollbar of the form will change focus to the bottom of the form.
Your code is iterating through every single record, from top to bottom. It goes to the bottom because that's where the code stops. That's fine, it's how Access works.
So, after that code, add the following:
Me.Recordset.MoveFirst
Or
DoCmd.GoToRecord acDataForm, Me.Name, acFirst

TreeView ActiveX control move to top left corner of the form when Enabled property is set back to True

I have a form containing multiple TreeView ActiveX controls with check boxes. Depending on the selected item in the first TreeView, I show different items in the other TreeViews.
I want to disable all the TreeViews if an uncheked item is selected in the first TreeView. To do so I check if the SelectedItem is checked in my update function. If not I set the Enabled property to false for all the TreeView except the first and exit. If it is checked I set the property back to true and update the TreeViews depending on the SelectedItem of the first TreeView.
It is working but my probleme is that when I set the Enabled property back to true, after it has been set to false, the TreeView is displayed in the top left corner. They stack in the corner so only the last one can be viewed.
I've search for a hint on how to fix this but had no luck. Any idea?
For future searchers:
I also had an issue with a TreeView jumping to the top left. In my case, I had a sub-report that was updated as well, and everything was fine until I clicked on the TreeView. Once I did, the view jumped to the top left.
Here's what I did to fix it:
Private Sub MyTree_GotFocus()
Me.MyTree.Top = Me.MyTree.Top
Me.MyTree.Left = Me.MyTree.Left
End Sub
Even though it just set the properties equal to their current values, updating the values re-anchored the element.
You could most likely just add those lines after whatever triggers the jump.
Me.MyTree.Enabled = True
Me.MyTree.Top = Me.MyTree.Top
Me.MyTree.Left = Me.MyTree.Left
I had a similar problem, the tree view would move when I switched from one tab to another. The only way I could get it to stop doing that was to put the TreeView control in its own sub-form (nothing in it but the TreeView control, and place that sub-form on the main form.

MS Access scrollbar on subform continuous forms not setting record focus

I can't seem to figure this out. I have a subform displaying continuous forms with a vertical scrollbar. When I click the scrollbar to move to a different record, the record never receives focus. The focus is still on the control of the record I left.
How to I control the record focus after using the scrollbar? The subform's On Current event does not fire.
Thanks!
The vertical scroll bar in a continuous MS Access form does not navigate among records. It simply changes which records are visible on the form. The black triangle within the record selector on the left side of the form indicates which record is currently "selected."
You can navigate records (ie, control the record focus, as you say) several different ways:
Click on the record selector* (the gray rectangle to the left of the form detail section)
Click on any enabled control within the form detail section
Use the navigation controls* at the bottom left of the form
Use [Tab], [Enter], or arrow keys to move through the individual controls on the form detail section; when you reach the last control in the tab order, your next [Tab]/[Enter]/[Down Arrow] key press will take you to the next record
* Note that both the Record Selectors and Navigation Buttons may be turned off on your form. On the form property sheet, ensure Record Selectors: Yes and Navigation Buttons: Yes.