Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop template being modified

Status
Not open for further replies.

bombdropVB

Programmer
Dec 3, 2002
59
0
0
GB
Hi all I'm writitng a template that adds a combo box tothe standard controlbar. but when saving the document it also wants to save changes to the .dot file also.

Code:
Private Sub Document_New()
   
        
Dim cboNames    As CommandBarComboBox
Dim objToolbar  As CommandBar

Dim conTelList  As ADODB.Connection
Dim recNames    As ADODB.Recordset
Dim strQuery    As String

    'establish the connection to DB
    Set conTelList = New ADODB.Connection
    conTelList.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Lvp-web\published\websites\Ganda intranet\_databases\phone_internal2000.mdb;Persist Security Info=False"

    strQuery = "Select Firstname,Surname,Location,ext,email"
    strQuery = strQuery & " From Employees where Firstname <>" & """ & """


    'Set an ope the recordset
    Set recNames = New ADODB.Recordset
    recNames.Open strQuery, conTelList


    'Get hold of the Standard CommandBar
    Set objToolbar = ActiveDocument.CommandBars("standard")

    'Insert the ComboBox into the Standard CaommandBar
    Set cboNames = objToolbar.Controls.Add(Type:=msoControlComboBox, _
        Temporary:=True)



    'Set Fill cboNames and set up properties
    With cboNames
        'Loop throught the Recordset and populate the ComboBox
        Do While Not recNames.EOF
            .AddItem recNames!firstname & Space$(1) & recNames!Surname
            recNames.MoveNext
        Loop 'While Not recNames.EOF

        .TooltipText = "Names"
        .Text = "Select Name"
        .OnAction = "Selection"
        .Width = 155
        .DropDownWidth = 155

    End With 'cboNames
'

End Sub

Why is the dot file being modified any help please would be great!!!!!
 
Hello BombdropVB

There are two things you can do, both quite simple.

Firstly tell the application where the changes are relevant to, using the CustomizationContext eg in Word you would put something like:

Application.CustomizationContext = ActiveDocument

That tells it where to store the changes (in this case the document based on your template), and put it near the top of your routine, somewhere before you set objToolbar.

Secondly you could add a simple statement at the end of your routine along the lines of:

Templates("Your Template Path\Your Template.dot").Saved = True

This simply fools the application into thinking that there haven't been any changes to the template. I also tend to put a statement such as this into the Document_Close sub of the template object just to be on the safe side.

Hope this gets helps

Asjeff
 
asjeff has a correct solution, and probably the best.

I have one question though.

If this is a document created from a template, why are you putting the combobox into the commandbar in the New document? Why not have the combobox already there (but empty of items) in the template itself? Then the created New document just has to populate it.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top