how to active the ribbon Tab automatically when the form opens[Access 2007]

J

Jason Jiang

Dear

I built a ribbon tab for a form. It works fine and when the form opening,
the ribbon will be loaded fine. But it would be focus (or active)
automatically. It still focus in the tab where I set now. Please
help.!!urgent.!!

Another question:

is the callbacks for the ribbon always in Modules? I remember in Access
2003, the callbacks function could be in the form class modules. If all the
callbacks should be in the Modules, does it mean we need distinguish which
form or report is active now?

Thank you very much.

Jason Jiang
 
A

Albert D. Kallal

Jason Jiang said:
Dear

I built a ribbon tab for a form. It works fine and when the form opening,
the ribbon will be loaded fine. But it would be focus (or active)
automatically. It still focus in the tab where I set now. Please
help.!!urgent.!!

I don't believe there is a way to do the above. The simply solution I use is
to create a whole new ribbon from scratch. and, I usually stick to one
"tab". You can have "several" groups display on the ribbon. so, presumably,
you would have your ribbon display + perhaps the filter + clipboard groups
(I don't see the need for much more).

I don't think it makes a lot of sense to load up a form, and add a new "tab"
to the existing ribbon..that going to either

a) fore the user to have to click on that tab (hence your question!)

b) if they do click on that tab, then they loose all the cut/past/filter
etc....

so, the solution so far is to simply load up a custom ribbon for form with
one tab....

Not the best solution but I don't believe there is a programme way to select
a tab right now...

I shall assume you know how to "look up" the names of other groups you want
to include in your ribbon.

So, right after your group (or, perhaps before makes more sense), you can
"steal" the existing groups you need, and *include* them in your custom
ribbon.

So,
<group idMso="GroupClipboard" />
<group idMso="GroupFindAccess" />
<group idMso="GroupSortAndFilter" />


The above is quite typcial of what you need (clipboard, find,
sorting/fitler). so, just include the above 3 with your ribbon...I not
likely the user needs all those other tabs anyway....

So, build your ribbon with the "start from scratch" = true:

eg:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="MyRibbonLoad">
<ribbon startFromScratch="true">
<tabs>
<tab id="Home" label="Home">

<group idMso="GroupClipboard" />
<group idMso="GroupFindAccess" />
<group idMso="GroupSortAndFilter" />

<group id="group1" label="group1">
<button id="button1" label="Buttion1"
getVisible="MyVisible"
getEnabled="MyEnable"
onAction="=MyTest1()" />

<button id="button2" label="button2" onAction="=Mytest2()"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>


So, in the above, we place the built-in groups we need before our custom
group with the buttons.

So, we just specify the above ribbon in the "other" tab of the forms
property. In the above, I do have two call backs (getvisble, and
getenabled...and they MUST be in a standard module.

However, the function MyTest1() can be in either the form, or the standard
public module (this is the SAME as to how it worked before).
Another question:

is the callbacks for the ribbon always in Modules? I remember in Access
2003, the callbacks function could be in the form class modules. If all
the callbacks should be in the Modules, does it mean we need distinguish
which form or report is active now?

Don't confuse the code that a menubar runs. As mentioned calling the
"on-action" code works the same as it did before. The new ribbon/version HAS
NOT changed this. That means the "on-action" setting can call code in your
current form, or a standard module. (which ever form has the focus is
searched for the code...so, one ribbon can do different things when
different forms has the focus..since the code will be run from the form). If
the code is not found in the form with the focus..then standard modules are
searched for the function name.

However, the so called "call backs" are used to enable, and disable
controls, that code MUST be in a standard code module.

I have a working solution that automatic makes a control collection, so you
can much enable/disables controls like you did before...

I already posted the code in this newsgroup...but will put a web page with
the code ASAP....
 
J

Jason Jiang

Dear Albert

Thank you very much.

About tab autofocus issue: yes, It seems I have to give up. I have too many
menu bottons in need. Microsoft thought everybody is using the 21' LCD. But
I still stick in my 13.3' laptop. -_-!! The ribbon bar is too big in my
screen. Anyway, thank you very much. Your "stealing strategy" is quite
lighten me.

I am still working on the callbacks issue:

here is my callbacks:

Public Sub onTest(ByVal control As IRibbonControl)
MsgBox ("aaa")
End Sub

It works fine in the standard module.

but I paste this to the form module. It shows "Couldn't find the callback
function" ( I am using the Chinese version, not sure what shows in English
version). And I also try this in form

Public Function onTest(ByVal control As IRibbonControl)
MsgBox ("aaa")
End Function

It also doesn't work.

Please help! Thank you very much

Jason
 
A

Albert D. Kallal

here is my callbacks:
Public Sub onTest(ByVal control As IRibbonControl)
MsgBox ("aaa")
End Sub

Where you are specify the above? As I CLEARY pointed out, any call back code
must be placed in a standard code module. However, the OnAction setting for
a ribbon DOES NOT need to be placed the standard code module, but can be
place in the forms code.

AGAIN:
* ONLY call back code need be placed in a standard code module

* the onAction setting for a button to run code is NOT a call back.


just set the on-action to your public function (which can be in standard
module, or forms module).

In my sample posted in this thread, I have

onAction="=MyTest1()"

So, just like you done for the last 10 ears with custom menu bars, simply
place your function in your form

eg:

Public Function MyTest

... you code goes here..there are NO parmaters paseed...the code just
runs


However, Getvisible is a call back, and that that does need to be public in
a standard code module...it can't be in the forms code...
 
J

Jason Jiang

Dear Albert

Thank you for get me very clear this. I finally understand what this mean
and made a successful trial.

I am new in Access 2007 and it's kinda hard to find completed document to
introduce access ribbon.




I couldn't find your posted code. I only could read after 2007-6-15's
thread. Could you re-posted again? or send me a mail by
jasonjiang9999(@)hotmail.com.

thank you again!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top