ActiveDocument.CommandBars picks the wrong CommandBar

D

Daniel McCarty

I have a quote template that pulls in parts and descriptions from a
database and turns them all into a nice quote, which is also merged and
linked with GoldMine. It has a custom toolbar and one the buttons on
the toolbar allows the user to pick a salesman and automatically
inserts the salesman's name and title, signature and next quote number.

After the user picks a salesman I'd like to disable the Select Salesman
toolbar button, since it will screw up the quote if they do it more
than once. So I save whether a salesman was picked as a custom
property in the quote, a la

Set docp = doc.CustomDocumentProperties
With docp.Add("qtFSalesman", False, msoPropertyTypeBoolean, True)
' We don't really need to do anything here, but we could...
End With

' Once the salesman is selected don't allow another selection.
CommandBars("Quotes").Controls(1).Enabled = False

Later, if the document is opened, code in Document_Open() does pretty
much the same thing:

' Read the custom document property "qtFSalesman" and allow or
' disallow the salesman selection based on the property value.
fSalesman = ActiveDocument.CustomDocumentProperties("qtFSalesman")
ActiveDocument.CommandBars("Quotes").Controls(1).Enabled = _
Not fSalesman

My problem is that users don't get the custom toolbar just by creating
a new document based on the template. So they go to Tools...Add-Ins
and explicitly add .dot template as a global template. When the code
runs it disables the toolbar in the _template_, not in the new
document.

How can I only disable the Salesman button on the toolbar of the new
document?

Thanks in advance,
Dan.
 
C

Cindy M -WordMVP-

Hi Daniel,

Set the CustomizationContext for the application to the document,
specifically, before changing the control's properties.
I have a quote template that pulls in parts and descriptions from a
database and turns them all into a nice quote, which is also merged and
linked with GoldMine. It has a custom toolbar and one the buttons on
the toolbar allows the user to pick a salesman and automatically
inserts the salesman's name and title, signature and next quote number.

After the user picks a salesman I'd like to disable the Select Salesman
toolbar button, since it will screw up the quote if they do it more
than once. So I save whether a salesman was picked as a custom
property in the quote, a la

Set docp = doc.CustomDocumentProperties
With docp.Add("qtFSalesman", False, msoPropertyTypeBoolean, True)
' We don't really need to do anything here, but we could...
End With

' Once the salesman is selected don't allow another selection.
CommandBars("Quotes").Controls(1).Enabled = False

Later, if the document is opened, code in Document_Open() does pretty
much the same thing:

' Read the custom document property "qtFSalesman" and allow or
' disallow the salesman selection based on the property value.
fSalesman = ActiveDocument.CustomDocumentProperties("qtFSalesman")
ActiveDocument.CommandBars("Quotes").Controls(1).Enabled = _
Not fSalesman

My problem is that users don't get the custom toolbar just by creating
a new document based on the template. So they go to Tools...Add-Ins
and explicitly add .dot template as a global template. When the code
runs it disables the toolbar in the _template_, not in the new
document.

How can I only disable the Salesman button on the toolbar of the new
document?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

Daniel McCarty

Cindy said:
Hi Daniel,

Set the CustomizationContext for the application to the document,
specifically, before changing the control's properties.

Hi Cindy,
Thanks, I'm sure that was part of my problem. I put the change in,
but I still seem to have two problems:
1. When closing the new document Word asks if I want to save changes
to the template
2. If I create and save a quote, then close it and create another
quote, the toolbar doesn't return to its original state like it should
from Document_Open().

I think that there's a problem with the way that the new documents
are opening from GoldMine. The fact that they open without a visible
toolbar and the user has to manually select one from Tools...Templates
and Add-Ins seems to indicate that something is still wrong. Any
ideas?

Thanks,
Dan.
 
C

Cindy M -WordMVP-

Hi Daniel,

No guarantees here, no experience with GoldMine and I'm short on time, so
forgive me if my answer is a bit compressed...
Thanks, I'm sure that was part of my problem. I put the change in,
but I still seem to have two problems:
1. When closing the new document Word asks if I want to save changes
to the template
Adding a TemplateObjectReference.Saved = True at the end of the proc
should make Word think that no changes need to be saved to the template
2. If I create and save a quote, then close it and create another
quote, the toolbar doesn't return to its original state like it should
from Document_Open().
You need to DELETE whatever you added on Document_Close? (Don't forget to
set the cutomizationcontext !)
I think that there's a problem with the way that the new documents
are opening from GoldMine. The fact that they open without a visible
toolbar and the user has to manually select one from Tools...Templates
and Add-Ins seems to indicate that something is still wrong. Any
ideas?
Hard to be sure, since there is a menu bar. But I'd just build displaying
the basic toolbars into the code?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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