Toolbar Drop Down Boxes

  • Thread starter Archie Dog via OfficeKB.com
  • Start date
A

Archie Dog via OfficeKB.com

I have created a custom toolbar with two drop down boxes.

The drop down boxes were initially created on the toolbar using code.

***********
Dim cmdB As CommandBar
Dim newButton As CommandBarButton

‘strUDTBar is a Public Constant containing the name of the toolbar as a
string
Set cmdB = Application.CommandBars(strUDTbar)

With cmdB
.Visible = True

With .Controls.Add(msoControlComboBox)
.Move cmdB, 4
.Width = intTBBranchWidth
.Caption = "Office"
.BeginGroup = True
.OnAction = "Populate_Employees"
End With

End With
***********
Subsequently, the system does not re-create the toolbar drop down boxes but
clears & re-populates them.

The first combo box contains a list of offices. This is re-populated every
time Word is loaded.

The office names are put into an array (declared as a Public variable as it
is used by a number of procedures) when the drop down list is created. The
contents of this array are then erased.

When the user selects an item in the first combo box, the second box is
populated with the names of employees in the selected office. Again, the
employee names are in a Public array and this is erased once the drop down
list has been populated.

The template containing the relevant code is in Startup & therefore loaded
when Word is first started. It is the only template loaded.

This all seems to work fine, as long as I don’t create a new document! The
‘New’ command is the standard MS Word one.

When I create a new document, the selected office remains correct. However,
the employee may either be blank and, if this occurs, there are no names in
the employee drop down list. Alternatively, the drop down box may pick up a
list of employees from a completely different branch.

If I go back to my original document, the values are correct. The results
can vary each time I create a new document.

I have put a break point in every single procedure to see if something is
inadvertedly kicking off code somewhere but it is not running any code when
it goes wrong.

I’m sure I’m missing something simple here but I’m darned if I can see what
it is.

I haven’t posted all the code as there is rather a lot of it. Do I I need to
supply more info?

Am at my wit's end! Any help very, very gratefully appreciated.

ArchieD
 
S

Shauna Kelly

Hi

Let's start here:
The template containing the relevant code is in Startup & therefore loaded
when Word is first started.
Fine. And that means that the template is loaded as a global template, or
add-in. And that means that its functionality is available to all documents
that the user may open or create.
It is the only template loaded.
Strictly speaking, this isn't true. When a .dot file is loaded as an add-in
(either because you put it in the Startup folder and Word did it
automatically, or because you loaded it manually using Tools > Templates and
Add-ins) then it is no longer acting as a template. That is, it's no longer
acting as the basis for a new document. It's now fulfilling a different
function: that of an add-in.

The code you're running does not explicitly tell Word where to save the
changes (ie the changes to the combo box lists). Obviously you need those
changes to be saved in your add-in. So use the
Application.CustomizationContext to tell Word where to save the changes.

This line, placed before any changes you make to commandbars or buttons will
do the trick:
Application.CustomizationContext = ThisDocument

In this case, ThisDocument refers to the file that holds the code.

When you've finished your changes, do this, to prevent the user getting a
'do you want to save' message:
ThisDocument.Saved = True


Finally, when you're testing, tick the box at Tools > Options > Save >
"Prompt to save Normal Template". If you're asked to save the normal
template when you close Word, and you otherwise know that you made no
changes to it, then it could be that your code is inadvertently saving
changes to normal.dot, and that you do not want.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
A

ArchieD via OfficeKB.com

Thanks for the suggestion, Shauna, but unfortunately that hasn't resolved the
problem.

Does anyone have any other ideas? Please :)

Thanks in advance
ArchieD

Shauna said:
Hi

Let's start here:
The template containing the relevant code is in Startup & therefore loaded
when Word is first started.
Fine. And that means that the template is loaded as a global template, or
add-in. And that means that its functionality is available to all documents
that the user may open or create.
It is the only template loaded.
Strictly speaking, this isn't true. When a .dot file is loaded as an add-in
(either because you put it in the Startup folder and Word did it
automatically, or because you loaded it manually using Tools > Templates and
Add-ins) then it is no longer acting as a template. That is, it's no longer
acting as the basis for a new document. It's now fulfilling a different
function: that of an add-in.

The code you're running does not explicitly tell Word where to save the
changes (ie the changes to the combo box lists). Obviously you need those
changes to be saved in your add-in. So use the
Application.CustomizationContext to tell Word where to save the changes.

This line, placed before any changes you make to commandbars or buttons will
do the trick:
Application.CustomizationContext = ThisDocument

In this case, ThisDocument refers to the file that holds the code.

When you've finished your changes, do this, to prevent the user getting a
'do you want to save' message:
ThisDocument.Saved = True

Finally, when you're testing, tick the box at Tools > Options > Save >
"Prompt to save Normal Template". If you're asked to save the normal
template when you close Word, and you otherwise know that you made no
changes to it, then it could be that your code is inadvertently saving
changes to normal.dot, and that you do not want.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
I have created a custom toolbar with two drop down boxes.
[quoted text clipped - 74 lines]
 
D

debbieprobert via OfficeKB.com

Found it! Or more to the point my extremely talented colleague found it.

The problem seems to only occur when Windows in Taskbar is switched on.
Switch it off and all is well.
Thanks for the suggestion, Shauna, but unfortunately that hasn't resolved the
problem.

Does anyone have any other ideas? Please :)

Thanks in advance
ArchieD
[quoted text clipped - 45 lines]
 

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