How to use a Command Button to navigate to a tab on my navigation form (1 Viewer)

dal1503

Registered User.
Local time
Today, 17:11
Joined
Apr 14, 2016
Messages
34
Hi,

I've got a navigation form [frmNavigation], and all my other forms appear as tabs (subforms I guess?) going along the top. The tabs I have are:

  • frmConsultations
  • frmFamilies
  • frmIndividuals

On the [frmConsultations] tab I want to add a Command Button that will take the user to the [frmFamilies] tab - basically duplicating the action of click on the [frmFamilies] tab at the top of my navigation form.

I am able to get it to open [frmFamilies] as a separate form, but ideally I want the button to just navigate to the tab/subform on the Navigation Form.

I know it may seem pointless to duplicate the action of clicking a tab, but the reason I'm doing it is to add buttons to act as 'frequent actions' - actions that a user would commonly want to perform from that particular form.

I've used macros in the past but can't seem to find the right action. I've seen a few solutions online using VBA code/modules, but I've never used these so I don't really know where to start with them :confused: I'd welcome a brief tutorial though if that's what I need to use to achieve what I want!

I hope this makes sense, any help would be greatly appreciated. If you need any further information please let me know and I will post it. Thanks
 

Minty

AWF VIP
Local time
Today, 18:11
Joined
Jul 26, 2013
Messages
10,372
On the command buttons properties select the Click event and select Event_Procedure code builder. That will put you in the VBA editor.
If you forms are actually tabs you probably only need to set focus to them by referring to the tabpage names. So the code would simply be

Me.YourTabPageName.Setfocus

However if your tabs are actually subforms or seperate forms the syntax becomes a little more complicated, it would help to know what they really are and possibly what the main form and sub form names are. The correct way to refer to the forms is best explained here - bookmark this page http://access.mvps.org/access/forms/frm0031.htm even after years of using access I still refer to this almost weekly.
 

dal1503

Registered User.
Local time
Today, 17:11
Joined
Apr 14, 2016
Messages
34
On the command buttons properties select the Click event and select Event_Procedure code builder. That will put you in the VBA editor.
If you forms are actually tabs you probably only need to set focus to them by referring to the tabpage names. So the code would simply be

Me.YourTabPageName.Setfocus

However if your tabs are actually subforms or seperate forms the syntax becomes a little more complicated, it would help to know what they really are and possibly what the main form and sub form names are. The correct way to refer to the forms is best explained here - bookmark this page http://access.mvps.org/access/forms/frm0031.htm even after years of using access I still refer to this almost weekly.


I originally had 3 forms: frmConsultations, frmFamilies and frmIndividuals. I then created a Navigation Form called frmNavigation with horizontal tab layout, and dragged my original 3 forms onto the frmNavigation form. Does this then cause my main form to be frmNavigation, and frmConsultations, frmFamilies and frmIndividuals to be sub forms?

Can I simply refer to the frmFamilies form as a whole, or would I need to refer to a particular control on that form e.g. the FamilyID text box?
 

Minty

AWF VIP
Local time
Today, 18:11
Joined
Jul 26, 2013
Messages
10,372
I'm afraid don't use the inbuilt navigation forms as it complicates things too much (IMHO) as you are now discovering.
Having had a little play it looks like your forms are indeed Subforms on tabs. So my first guess was correct, but because you are now on a Sub Form you may need to use

Me.Parent.YourNavigationButtonName.Setfocus

Have a play - make a back up and it won't break anything!
 

dal1503

Registered User.
Local time
Today, 17:11
Joined
Apr 14, 2016
Messages
34
I'm afraid don't use the inbuilt navigation forms as it complicates things too much (IMHO) as you are now discovering.
Having had a little play it looks like your forms are indeed Subforms on tabs. So my first guess was correct, but because you are now on a Sub Form you may need to use

Me.Parent.YourNavigationButtonName.Setfocus

Have a play - make a back up and it won't break anything!

What do you use instead? Do you just create a switchboard manually that has buttons to open the individual forms? I'm getting the feeling that might be a lot easier!


I tried your code and it 'highlighted' the tab (if that's the right word to describe it) but didn't actually switch to that tab :(
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:11
Joined
May 7, 2009
Messages
19,246
on the click event of your button, put this code:

private sub button_click()
' you find out first which button tab is frmFamilies in (NavigationButtonN)
[Forms]![frmNavigation]![NavigationButtonN].Setfocus
SendKeys "{Enter}"
end sub
 

dal1503

Registered User.
Local time
Today, 17:11
Joined
Apr 14, 2016
Messages
34
on the click event of your button, put this code:

private sub button_click()
' you find out first which button tab is frmFamilies in (NavigationButtonN)
[Forms]![frmNavigation]![NavigationButtonN].Setfocus
SendKeys "{Enter}"
end sub

This worked, thanks!
 

Minty

AWF VIP
Local time
Today, 18:11
Joined
Jul 26, 2013
Messages
10,372
What do you use instead? Do you just create a switchboard manually that has buttons to open the individual forms? I'm getting the feeling that might be a lot easier!


I tried your code and it 'highlighted' the tab (if that's the right word to describe it) but didn't actually switch to that tab :(

I, and a I suspect most regular users create their own menu / navigation Forms. I normally use a switchboard style form, with command buttons to do the common tasks (Frequently used form opening) and then sub- menus for the more obscure less used items.

The problems you have encountered is one of the reasons!
 

Users who are viewing this thread

Top Bottom