Show custom ribbon in design mode (shift open) - access 2013 - ms-access

Recently I created a custom ribbon for my access 2013 database. In my old access 2000 database I could always see the custom toolbars even if I opened the database with shift (designer mode - so I can see the tables, etc.).
In access 2013 however, I cant see my custom created ribbon when I open it with shift enter (I can only see the file, create, external data and help tools in the ribbon), is it possible to see the custom ribbon in designer mode (shift open)?
Here some additional information:
The ribbon is build in XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnMainRibbonLoad" >
<ribbon startFromScratch="true">
<tabs>
<tab id="tabBogus" label="Bogus" visible="false">
<group id="oPrint" label="Print- en pagina instellingen" >
<button idMso="PrintDialogAccess" size="large" label="Afdrukken" imageMso="PrintDialogAccess" getEnabled="MyEnabled" />
<button idMso="PageSetupDialog" size="large" label="Pagina instellingen" getEnabled="MyEnabled" />
<control idMso="FilePrintPreview" label="Print Preview" getEnabled="MyEnabled"/>
<button id="PrintKies" label="Standaard printer" screentip="Standaard printer" supertip="Stel de standaard printer in." imageMso="FilePrintQuick" onAction="ribbonOpenForm" getEnabled="MyEnabled" tag="PrinterKiezen"/>
</group>
</tab>
The code to load the ribbon is as follows:
Private m_ribbon As IRibbonUI
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub OnMainRibbonLoad(OPSRibbon As IRibbonUI)
'handles the OnLoad callback of the customUI element
'and saves the IRibbonUI object reference to m_ribbon
Set m_ribbon = OPSRibbon
end sub
Public Property Get MainRibbon() As IRibbonUI
'global property that re-exposes the ribbon system-wide
'so consumers can call the IRibbonUI.Invalidate method as required
Set MainRibbon = m_ribbon
End Property
Private Sub Form_Current()
'consumes the global object reference to the ribbon
'calls its invalidate method
'and while rebuilding the ribbon your ToolEnabled() method will be called
'to enable, or not, your control
MainRibbon.Invalidate
End Sub
The custom ribbon is also set in the access 2013 options:
Current database --> Ribbon options -->Name Ribbon --> my ribbon
Any clue how I can load the custom ribbon in designer mode as well? With a button or something perhaps?

I would recommend avoid using Shift key for opening application in debug mode. Set something like “Debug” flag in the application, with this flag load debug version of custom ribbon (with startFromScratch="false") and bypass, for instance, logon screen. For release change ribbon to production version.
The other way – use LoadCustomUI method on form or in macro for loading your menu after starting the application with Shift key

Related

How do I click a button on a webpage through VBA?

I am trying to use click a button through vba but it tells me that the "Object doesn't support this property or method".
My VBA code right now is:
IE.document.getElementByType("button").getelementByClass("qm_historyTab_GoButton").Click
The HTML for the button is:
<button class="qm_historyTab_GoButton" type="submit" style="font:normal 11px tahoma,arial,helvetica,sans serif;">
<span class="qm_historyTab_GoButtonText">GO</span>
</button>
Try this:
IE.document.getElementsByTagName("button") _
.getelementsByClassName("qm_historyTab_GoButton")(0).Click
Both of the getXXX methods return a collection of items (even if there's only one match in the document) so to address a single item from the last one in order to click it you need to add the (0)
EDIT: if the aim is to submit the form then this will also work
IE.document.getElementById("qm_historyForm_7871").submit
or as there's only one button with that classname:
IE.document.getElementsByClassName("qm_historyTab_GoButton")(0).Click
Ok so I found the solution in this specific instance. The button is a submit type and sends a message using HTMLInputElement.
What I needed to do was add "Microsoft HTML Object Library" to my references and utilize those features.
I had to create the variable that would send the response:
Dim htmlInput As MSHTML.HTMLInputElement
I couldn't figure out how to refer to this specific element individually so I grabbed everything with it's class name.
For Each htmlInput In IE.document.getElementsByClassName("qm_historyTab_GoButton")
If Trim(htmlInput.Type) = "submit" Then
htmlInput.Click
Exit For
End If
Next htmlInput
Then I had the program cycle through each item in the series and send a submit response. Since this was the only one with the class name, I got lucky.
So anyways, that's how I solved the problem.

VB WebBrowser click button

On this web page: https://www.youtube.com/upload_defaults
I would like to call a function and then click the "Save" button in the upper right corner.
There is no ID or Name. How can I do this?
You can use the distinct CSS class of the button: account-save-button
In VB.NET, use HtmlDocument.GetElementsByTagName like this:
Private Sub ClickSaveButton()
If (WebBrowser1.Document IsNot Nothing) Then
Dim Elems As HtmlElementCollection
Dim WebOC as WebBrowser = WebBrowser1
Elems = WebOC.Document.GetElementsByTagName("BUTTON")
For Each elem As HtmlElement In Elems
Dim CssClass As String = elem.GetAttribute("classname")
If ((CssClass IsNot Nothing) And (CssClass.Length <> 0)) Then
If CssClass.ToLower().Contains("account-save-button") Then
elem.InvokeMember("click");
Exit For
End If
End If
Next
End If
End Sub
To verify it with just a web browser, try this from your browser's developer console; it works because youtube uses jQuery:
$(".account-save-button").click();
Or pure javascript: document.getElementsByClassName('account-save-button')[0].click();
For reference, here is the button's markup:
<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-primary account-save-button account-action-button" type="submit" onclick=";return true;"><span class="yt-uix-button-content">Save</span></button>
Other thoughts:
This is basically screen scraping, which can lead to brittle applications when the page changes, etc.
Google may already have a web service API for what you are trying to accomplish.. but that's a good question:
What exactly are you trying to accomplish? What is the context? We may be able to suggest a better alternate solution.
Update:
I checked the Youtube API Reference, but I don't see anything for setting preferences for upload defaults.

Dynamically adding listitems to a select tag in ASP.NET

I'm trying to do something I thought would be very simple - dynamically add some options in a select tag using ASP.NET.
I've written my code as:
<select id='cmbDuration'>
<% Dim periods As Generic.List(Of Models.Duration) = DBSupport.getDurations
For Each d As Models.Duration In periods
Response.Write("<option value='" & d.id & "'>" & d.name & "</option>")
Next
%>
</select>
All is well and the data returned by my db layer appear in my select tag.
Later on, I remembered to add a runat = "Server" tag, to process my data in my code-behind post. But, after adding that, no options are displayed. Checking the resulting source code, I see no options added to it as well.
What is the problem here? Why no options are shown when runat = "Server" is added?
Why are you talking about processing data in your code-behind post, but writing in-line code to generate list items? You should be binding your dropdown list in the code-behind:
ASP.NET
<asp:DropDown ID="cmbDuration" DataTextField="Name" DataValueField="ID" runat="server" />
CODE-BEHIND (in Page_Load)
If Not Page.IsPostBack Then
Dim periods As Generic.List(Of Models.Duration) = DBSupport.getDurations
cmbDuration.DataSource = periods
cmbDuration.DataBind()
End If
So, the way I understand this, is that adding the runat="Server"
attribute will result in my control being available for subsequent
process only in code-behind
No, adding runat="server" tells visual studio and the compiler that this control will be represented as a server control. It add's a server control into your .designer.cs file:
/// <summary>
/// Image3 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Image Image3;
this process happens at design time.
Your code (everything inside the <%%>) happens at runtime. So your trying to build dynamic HTML using your code block. So the designer has no idea what your going to add, how many controls are your adding? How do I represent this? So it can't build the server side control code. So it doesn't. It also causes the runtime code to be unable to process the ViewState. Again it doesn't know what your controls are supposed to represent.
So you can't simply:
<select id='cmbDuration' runat='server'>
<% Dim periods As Generic.List(Of Models.Duration) = DBSupport.getDurations
For Each d As Models.Duration In periods
Response.Write("<option value='" & d.id & "' runat='server'>" & d.name & "</option>")
Next
%>
</select>
This is simply invalid ASP.Net syntax. You can't write to the code behind at runtime in this manner. Before your for-loop is executed .Net has already built up what code behind blocks it needs, so you can't add to this.
I'm not going to repeat what #Scott has already answered but this is what you need to do.
The problem is you are writing to ASPNET's "Response Stream" by using the function Response.Write(), which will cause the output'd option tags to appear at the very very top of the page where the Response Stream is printed. This will appear even above the HTML declaration tag. (Examine your HTML source code to see) If you wish to write output directly to the ASPX page, try this:
<select id='cmbDuration'>
<%For x As Integer = 0 To 5%>
<option><%=x%></option>
<%Next%>
</select>
If this helps, or not, please let me know!

Umbraco - Render .Net User Control (ascx) macro with Razor

I have a razor script in Umbraco that is quite complex and I want at some point of it to render a macro in it.
The macro which is called SuggestionBox is actually a user control (.ascx) and traditionally this is referenced on the template using
<umbraco:macro Alias="SuggestionBox" language="cshtml" runat="server"></umbraco:macro>
But now I need to call it from the razor script instead so I tried;
#Html.Raw(umbraco.library.RenderMacroContent("SuggestionBox", Model.Id))
as well as:
#RenderPage("SuggestionBox")
No luck so far as I'm sure I'm using these wrongly.
I read somewhere it might be infeasible if the page is wrapped in a masterpage.
It works if I add it to the Template like I traditionally would:
<umbraco:macro Alias="EventsRenderer" language="cshtml" runat="server"></umbraco:macro>
<div class="talkingPointPanel">
<h3><umbraco:Item field="talkingPoinstSuggestionText" runat="server"></umbraco:Item></h3>
<umbraco:macro Alias="SuggestionBox" language="cshtml" runat="server"></umbraco:macro>
</div>
Where EventsRenderer renders the page that should ideally contain the SuggestionBox.
using
#Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"SuggestionBox\" />", Model.Id))
Gives me this error:
<!-- Error generating macroContent: 'System.Web.HttpException (0x80004005): HtmlForm cannot render without a reference to the Page instance. Make sure your form has been added to the control tree.
at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at umbraco.presentation.templateControls.Macro.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at umbraco.library.RenderMacroContent(String Text, Int32 PageId)' -->
Any ideas?
<umbraco:Macro runat="server" language="cshtml">#{
HtmlTextWriter writer = new HtmlTextWriter(this.Output);
var navigation = new umbraco.presentation.templateControls.Macro();
navigation.Alias = "Navigation";
navigation.MacroAttributes.Add("ulclass", "art-vmenu");
navigation.MacroAttributes.Add("level", 2);
navigation.RenderControl(writer); }</umbraco:Macro>
Try something like this. It works for me ... I have made a Navigation macro. Be Aware though your variables should be given in toLower, if caps are used, the parameters will not come through.
In Umbraco 4.10+ To call a macro inside Razor script, use:
#Umbraco.RenderMacro("macroNameHere", new { propertyName1 = CurrentPage.pageProperty }))
Try something like this:
#Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"SuggestionBox\" />", Model.Id))

Disable System Ribbon in CRM 2011

I would like to conditionally disable a System Ribbon = AddNew in a CRM 2011 form with javascript. That means if the statusCode is X or Y disable the Ribbon, how could I do this?
I tryed to get the ID of the Ribbon in order to change the classname of the Ribbon to disabled, but I got Null because the Ribbons are loaded asychronously!
To expand on Anwar's answer, the key to getting this to work is to intercept and repurpose the functionality of the AddNew ribbon button, but once you do, there won't be any need for hacking the Ribbon DOM. Below are a few steps that you can take to get there.
1) Create a solution with the Application Ribbon included.
2) Find in the SDK the sample ribbon for the Application Ribbon or build it yourself using the solution included in the SDK.
\sdk\resources\exportedribbonxml
\sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml
3) Find in the Application Ribbon template the control you're interested in, which I assume in this case is the AddNew button in entity subgrids. Repurpose this control in a CustomAction and make the location of the CustomAction the same name as the control you want to repurpose.
<CustomAction Id="YourOrg.SubGrid.{!EntityLogicalName}.AddNewStandard"
Location="Mscrm.SubGrid.{!EntityLogicalName}.AddNewStandard">
<CommandUIDefinition>
<Button Id="Mscrm.SubGrid.{!EntityLogicalName}.AddNewStandard"
Command="Mscrm.AddNewRecordFromSubGridStandard" Sequence="20"
LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew"
Alt="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew"
Image16by16="/_imgs/ribbon/NewRecord_16.png"
Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1"
ToolTipTitle="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipTitle"
ToolTipDescription="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipDescription" />
</CommandUIDefinition>
</CustomAction>
4) Find in the Application Ribbon template the definition of the command of this button, and using the exact definition as the basis of a new CommandDefinition, add in your own custom rule (in this case, a new EnableRule).
<CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard">
<EnableRules>
<EnableRule Id="Mscrm.AppendToPrimary" />
<EnableRule Id="Mscrm.EntityFormIsEnabled" />
<EnableRule Id="YourOrg.DisableNewStuff" /> <!--your custom rule-->
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.CreateSelectedEntityPermission" />
<DisplayRule Id="Mscrm.AppendSelected" />
<DisplayRule Id="Mscrm.HideAddNewForChildEntities" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard"
Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="PrimaryEntityTypeCode" />
<CrmParameter Value="FirstPrimaryItemId" />
<CrmParameter Value="PrimaryControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
5) Here is where Anwar's answer comes in: using both the OrRule and the ValueRule, define your EnableRule to check on the statuscodes of the entity. The linked demonstration relates to a new ribbon button, but the same rules work for repurposed ribbon controls as well.
Publish your changes when you're done and your ribbon should be all set. Because I'm not sure how familiar you are with RibbonXml, I'll also mention that Microsoft has some comprehensive walkthroughs that are pretty helpful (after much time studying them!) in picking it up.
This article explains exactly what your are looking for.
Please follow this link
How To Use "ValueRule" and "OrRule" in Ribbon Customizations - CRM 2011
This is how i hide the delete button on invoice form, based on status code, onload of the form:
var statusVal = Xrm.Page.getAttribute("statuscode").getValue();
if (statusVal==4 || statusVal==6) {
//Disable delete button
var x =top.document.getElementById("invoice|NoRelationship|Form|Mscrm.Form.invoice.Delete-Medium");
x.style.display='none';
You can get the id of the element span, which you want to hide from the source of the page.