UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Adding New Control To Command Bar In Subform, Access 2016    
 
   
Screamer58
post Jul 5 2018, 09:53 AM
Post#1



Posts: 7
Joined: 16-January 18



I have a subform control in my main form which has a query as the data source object. I want to add a control to the right click command bar that appears when a query row is selected. To achieve this I've pinched some code and put into the On Enter event of the subform, viz,

Private Sub Subform_StockSummary_Enter()

Dim cbr As CommandBar
Dim cbrButton As CommandBarControl

Set cbr = Application.commandbars("Form Datasheet Row")

' Check to see whether the item already exists, and if so exit the sub

On Error Resume Next

' Attempt to delete the item if it already exists
' if it doesn't exist, this will raise an error which will be ignored

cbr.Controls("Check this out").Delete
If Err.Number <> 0 Then Err.Clear

With cbr

Set cbrButton = cbr.Controls.Add(1, , , , True)
With cbrButton
.BeginGroup = True
.Caption = "Check this out"
.OnAction = "=CheckThisOut()"
End With

End With
End Sub


I am making the assumption that the name of the command bar control that appears when a row is right clicked is Form Datasheet Row - does anyone know if this is correct - should I be using a different command bar for a query data source object in a subform? When I use this code I have checked that the new control item (called "Check this out") is added and it is - BUT the item does not appear on the menu! Very frustrating! I have searched in vain for a solution - can anybody help please? Thank you.
Go to the top of the page
 
theDBguy
post Jul 5 2018, 10:03 AM
Post#2


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Welcome to UtterAccess!
welcome2UA.gif

I can't find my list of command bar names right now, but this article should help you list them out and find the correct name you need to use in your code.

Hope it helps...
Go to the top of the page
 
Screamer58
post Jul 5 2018, 11:04 AM
Post#3



Posts: 7
Joined: 16-January 18



Hi DBGuy....thank you for your reply. I have seen this article already and printed out all of the command bar names (of which there are many) but to me the most likely candidate still seems to be Form Datasheet Row which has exactly the controls that appear when I right click a selected query row in the subform. However, I am still obviously missing a trick! Is there a clever way to trap which command bar has been activated?

I have looped around the the command bars and checked which have 6 items like the one I am seeing that start with the caption New Record using

If (cb.Controls.Count = 6) Then
If (cb.Controls.Item(1).Caption = "Ne&w Record") Then
Debug.Print cb.Name
End If
End If

Only two exists that satisfy this, viz

Form Datasheet Row

and

Table Design Datasheet Row

I have tried using the latter just in case but still no luck.....I must be doing (or not doing something) really obvious. Do I need to set special permissions to modify existing command bars?
Go to the top of the page
 
theDBguy
post Jul 5 2018, 11:12 AM
Post#4


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Re: "Do I need to set special permissions to modify existing command bars?"

Good question. The one person I know who can answer it has a tool for creating command bars easier. I'll see if I can ping him for you.

In case you're interested, you can check out his Shortcut Tool website

Cheers!
Go to the top of the page
 
theDBguy
post Jul 5 2018, 11:19 AM
Post#5


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Okay, message sent. Hopefully, he's available today.
Go to the top of the page
 
post Jul 5 2018, 11:36 AM
Post#6








Your code looks right to me, so it may be that you have the wrong commandbar. Although you might want to add a line:

.Visible = True

inside the With/End With code segment.

In addition to the Access Shortcut Tool mentioned by thDBguy, I've written a number of articles on shortcut menus which might be of assistance. The 3rd article in the series is located here, focuses on using Built-in commandbars, and even has code which will add a "What's This" item to each of the commandbars, which will show up as the last item in each shortcut menu, and when clicked, will give you the name of the commandbar that is currently displayed.

Part 2 of the series talks about creating your own

Part 1 discusses commandbars in general, and Part 4 discusses using shortcut menus in a runtime environment.

HTH
Dale
Go to the top of the page
 
theDBguy
post Jul 5 2018, 11:39 AM
Post#7


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Hi Dale,

Thanks for the assist!
Go to the top of the page
 
Screamer58
post Jul 5 2018, 11:50 AM
Post#8



Posts: 7
Joined: 16-January 18



Thank you fyed and dbguy for your help....I will check out your articles and try the What's This? trick and let you know how I get on......Cheers!
Go to the top of the page
 
Screamer58
post Jul 6 2018, 12:07 PM
Post#9



Posts: 7
Joined: 16-January 18



OK...the What's this code did the trick! What I was looking for was

Query Design Datasheet Row

I led myself up the garden path a little because I assumed that all of the controls on the bar would be visible. This is not the case for Query Design Datasheet Row because it actually has 8 items, two of which are not visible, viz,

Recon&vert

and

Han&gui Hanja Conversion

whatever these are??!!

So, my code now works - thank you so much! I know I will be coming back to use this code again! Please have a beer on me.... cheers.gif
Go to the top of the page
 
theDBguy
post Jul 6 2018, 12:11 PM
Post#10


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Congratulations! Glad to hear you got it sorted out. Good luck with your project.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    18th August 2019 - 04:34 PM