Access: change subform based on button press - ms-access

Im pretty new to programming for MS Access and Visual basic. I'm trying to create a form that will change what the subform is based on a toggled option press.
I have attached pictures of the simple form I'm trying to do and gotten some code off tutorial sites that have shown an example of how to do it but I'm not sure if I should have the subforms pre-created or make the button load the form when clicked.
Option Compare Database
Private Sub Option0_Click()
End Sub
Private Sub Toggle11_GotFocus()
Form1!Testform1.SetFocus
End Sub
Private Sub Toggle12_GotFocus()
Form1!Testform2.SetFocus
End Sub
I know this code isn't all that's needed but I can't seem to find a good place to start to find out what needs to be done with this.

Newer versions of Access seem to hide subform tabs when you open a form, but there is a tab stop property for the childforms. I set the property for that to yes and then for one of the child forms to set the tab index to 0 and the other to 1. You can toggle between the forms using Ctrl Tab when you do this. If the Child Form tabs are not visible when you open the main form, Ctrl Tab will also make them visible allowing you to click on the tabs.

Related

Hiding the Navigation Pane cause a problem when exiting the database

I just found something strange with MS-Access 2016. I have a database with 2 forms: one hidden, one for a menu. The autoexec will open the hidden form and that one will open the menu form.
I unchecked some options, under Current Database e.g. [Display Navigation Pane] and [Allow Full Menus].
I have an exit button/command on the menu form. On Click, it calls DoCmd.Quit. But before exiting, I am getting an MS-Access window asking for the parameter that is normally when the form open, not when it is closing.
After doing a lot of testing and I mean a lot, I realised that the problem is related to the fact that I am disabling the [Display Navigation Pane]. If I keep the navigation pane, but instead I unchecked all Object Type, then everything works correctly.
So, my question is why disabling the navigation pane can create something like that and is there a way to fix it?
Yes, my solution works, but I don’t like it since users can open and close the navigation pane using the shutter bar; nothing shows but it is still distracting and users can call for support.
The problem is not related to the fact that the first form is hidden, but because it is open. If I add a DoCmd.Close acForm, “F_Parameter” before my DoCmd.Quit then it works.
It is easy to reproduce the problem:
Create a new database
Create two forms:
F_Parameter
F_Menu
Create a Macro named Autoexec:
OpenForm
Form Name: F_Parameter
Window Mode: Hidden
In form F_Parameter create an event On Load
Private Sub Form_Load()
DoCmd.OpenForm “F_Menu”
End Sub
In form F_Menu create a Button named Btn_Exit with an event On Click
Private Sub Btn_Exit_Click()
DoCmd.Quit
End Sub
In form F_Menu create an event On Load
Private Sub Form_Load()
MsgBox “Hello”
End Sub
go File, Options, Current Database and
uncheck Display Navigation Pane and
uncheck Allow Full Menus
Save, exit and open the database:
You will get a “Hello” because the F_Menu form open, now click on the exit and you will get another “Hello”. This second one should not be there because the form should be closing not opening.
I was able to reproduce the issue described. I don't think it has anything to do with the Navigation Pane.
This is happening because while the DoCmd.Quit event is occurring, the hidden F_Parameter form is becoming "unhidden" in order for Access to close it. This causes the F_Parameter Form.Load event to run, which is essentially opening F_Menu, thus causing the Form.Load event on F_Menu to run.
I was able to solve this by first explicitly closing F_Parameter, then quitting:
DoCmd.Close ObjectType:=acForm, ObjectName:="F_Parameter", Save:=acSaveNo
DoCmd.Quit

lock navigate pane in ms access

We are working on a project in MS-Access 2010, where users will be using switchboard as a main menu for navigation and will work in forms. We protected each form with login and password so the user can only access his/her records in a form (using vba macro inside MS-Access).
Now we would like to lock the control pane so noone can access objects like tables and queries. Does anyone have an idea how to do it in MS-Access?
Thanks for any ideas.
Home>Options>CurrentDatabase>
uncheck 'Use Access special keys'
uncheck 'Display Navigation Pane'
And perhaps also:
uncheck 'Allow full menus'
uncheck 'Allow default shortcut menus'
build custom ribbon
make sure users don't know about shift key bypass or else distribute executable ACCDE
if you are looking to do this programatically, then this will do it:
Call DoCmd.LockNavigationPane(True)
however, you are probably better off hiding the navigation window and also following some of the suggestions by June7.
An easy solution couild be simply setting the forms modal property to true in the form opening event like so:
Private Sub Form_Open(Cancel As Integer)
' Go Modal to Lock Navigation Pane
Me.Form.Modal = True
' Hide Navigation Pane
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
' Hide Ribbon
DoCmd.ShowToolbar "Ribbon", acToolbarNo
End Sub
Granted setting a form to Modal may not fit every situation but if you have a startup/ switchboard style form which opens all other forms then this could be a solution for you.

Access Navigation Control BrowseTo "The command or action 'BrowseTo' isn't available now. Error 2046

Using MSAccess 2016 64 bit with SQL SERVER Express 2014 backend.
I have a form "frm_Navigation" with a subform control "NavigationSubform" and a Navigation control.
There are several forms for different tasks within the database that are loaded into the NavigationSubform by clicking the buttons on the Navigation control.
Some of the navigation is managed from the Navigation Control, but some is initiated from a subform. When the user clicks a button on the control, it appears "pressed", but when I navigate using the following, I am not able to make the button appear pressed without changing the colour on the button.
This is how I am currently navigation from a subform:
Form_frm_Navigation.NavigationSubform.SourceObject = "frm_SearchResults"
Form_frm_Navigation.lbl_Header.Caption = "Search Results"
I have read the following posts, but sadly I'm not able to accomplish what I am trying to do
https://blogs.office.com/2010/02/23/access-2010-browseto-docmd-and-macro-action/
http://www.utteraccess.com/forum/index.php?showtopic=1986422
navigating to a different tab in navigation subform
Opening subform within navigations (ELI5)
Main form: frm_Navigation
subform Control on Main from: NavigationSubform
Subform containing code: frm_Search
Form I am trying to open: frm_SearchResults
DoCmd.BrowseTo acBrowseToForm, "frm_SearchResults", "frm_Navigation.NavigationSubform"
Error '2046': The command or action "BrowseTo" isn't available now.
Expected outcome: frm_Search is loaded in the subform control of frm_Navigation by default. After the user enters criteria in the search fields on the frm_Search and clicks btn_search the results are populated into a table, then the frm_SearchResults is opened to display the found records.
I have tried setting the focus to the Main form first, clearing the source of the NavigationSubform, setting the source of the NavigationSubform to the form I am trying to open (I read somewhere that the form must be open) and several permutations of the BrowseTo arguments.
EDIT 2016-07-04 16:04 GMT
It works now as long as the Navigation form is first closed, then reopened. It is not elegant, but the Navigation button now lights up to indicate which is "selected".
Excerpt of code in "frm_Search", a subform of "frm_Navigation" occupying the "frm_Navigation.NavigationSubform"
Is there a way to achieve this without closing the navigation form?
DoCmd.Close
DoCmd.OpenForm "frm_Navigation"
DoCmd.BrowseTo acBrowseToForm, "frm_SearchResults", "frm_Navigation.NavigationSubform"

Setting focus on a sub form

I have two sub forms embedded in control (the one that looks like a set of folders allowing you to change from tab to tab.. Sorry I don't know the name in English)..
Both sub forms are embedded on one sheet, I would like that immediately after executing a routine, I wrote on one of the subforms, that the set focus then goes to the other sub form.
For some strange reason I can't get it to work. The sub form and field I'm trying to go to are frmObjectives03 and Effective_date.
I tried:
Forms!frmObjectives03!Effective_date.Form.SetFocus
but it doesn't work.
I would appreciate any insight.
Thank you,
The control you speak of is a Tab control.
Because frmOjective03 is opened as a subform, it is not part of the Forms collection. Instead you can use Forms!MainForm!frmObjectives03.Form!Effective_date.SetFocus from anywhere, or Me!frmObjectives03.Form!Effective_date.SetFocus from within the main form or Me.Parent.Form!frmObjectives03.Form!Effective_date.SetFocus from the sibling subform.
If these are not working for you, please check the name of the subform control in your main form (because it may be Child17 instead of frmOjective03). Open the main form in design view, click on the subform ONCE and look in the Properties->Other->name.

Openning a new form from a tab

I'm creating forms with VBA/Access to access my database.
In a form, I have a *lst_sinistres* listbox that displays the results of my SQL query and when I doubleclick on one of the results it opens me another form with thanks to this code
Private Sub lst_sinistres_DblClick(Cancel As Integer)
DoCmd.OpenForm "F_SINISTRE_MRH", acNormal, , , , , Me.lst_sinistres.Value
End Sub
I wanted to change my form, and add tabs to make it more ergonomic. So I placed my *lst_sinistres* listbox inside a tab.
The problem is that when I doubleclick on one of the results in this listbox (now placed in the tab), the form *F_SINISTRE_MRH* does not open.
Does someone have an idea of ​​where the problem might come?
Thank you
A quirk of VBA control events is that event code can become detached from the control object. Things that cause this tend to be re-naming controls and copy/pasting similar code between controls. To move your listbox onto a tab control you needed to cut and paste it temporarily. That broke the link between the written code and the object name. When the code and object are properly linked, [Event Procedure] shows up in the property sheet (as suggested by #4dmonster).
If you are in the VBA editor, choosing Debug->Compile will search through all the code and re-link event code with like-named controls. This step is worth a try before re-writing because you may end up with orphan blocks of
Private Sub OldControlName_DblClick(Cancel As Integer)
MsgBox "Why don't I work anymore?"
End Sub
that are treated as Form-level subroutines that just happen to never be called.
pT