VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "SmartDoc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Option Base 0
Implements SmartTagLib.ISmartDocument

' Namespace / Namensraum

Private Const NAMESPACE As String = _
  "http://www.KAP24Beispiel.com/BSP02"

' namespace#element

' Diese eindeutige Identifikationen in einem
' Konstantwert festhalten
Private Const SCHEMA As String = _
  NAMESPACE & "#actionPertainsToEntireSchema"
Private Const KUNDE As String = _
  NAMESPACE & "#Kunde"
Private Const BETREFF As String = _
  NAMESPACE & "#Betreff"
Private Const BESTELLUNGEN As String = _
  NAMESPACE & "#Bestellungen"

' Anzahl der namespace#element-Einheiten

Private Const NUM_TYPES As Integer = 5

' namespace#element IDs

Private Const SCHEMA_ID As Integer = 1
Private Const KUNDE_ID As Integer = 2
Private Const BETREFF_ID As Integer = 3
Private Const BESTELLUNGEN_ID As Integer = 4

' Control ID constants
' Ein ID-Konstantwert für jedes Steuerelement,
' das in der Lösung/Aufgabenbereich eingesetzt wird

Private Const SCHEMA_HELP As Integer = 101
Private Const KUNDE_HELP As Integer = 201
Private Const KUNDE_SEPARATOR1 As Integer = 202
Private Const KUNDE_COMBO As Integer = 203
Private Const KUNDE_FIRMA_TEXTBOX As Integer = 204
Private Const KUNDE_STRASSE_TEXTBOX As Integer = 205
Private Const KUNDE_ORT_TEXTBOX As Integer = 206
Private Const KUNDE_REGION_TEXTBOX As Integer = 207
Private Const KUNDE_PLZ_TEXTBOX As Integer = 208
Private Const KUNDE_LAND_TEXTBOX As Integer = 209
Private Const KUNDE_KONTAKTPERSON_TEXTBOX As Integer = 210
Private Const KUNDE_POSITION_TEXTBOX As Integer = 211
Private Const KUNDE_INSERT_BUTTON As Integer = 212
Private Const BETREFF_HELP As Integer = 301
Private Const BETREFF_SEPARATOR1 As Integer = 302
Private Const BETREFF_TEXTBOX As Integer = 303
Private Const BETREFF_INSERT_BUTTON As Integer = 304
Private Const BESTELLUNGEN_HELP As Integer = 401
Private Const BESTELLUNGEN_SEPARATOR1 As Integer = 402
Private Const BESTELLUNGEN_KUNDE_CAPTION As Integer = 403
Private Const BESTELLUNGEN_KUNDE_LABEL As Integer = 404
Private Const BESTELLUNGEN_OPTIONS As Integer = 405
Private Const BESTELLUNGEN_ZAHL_TEXTBOX As Integer = 406
Private Const BESTELLUNGEN_INSERT_BUTTON As Integer = 407
Private Const BESTELLUNGEN_SEPARATOR2 As Integer = 408
Private Const BESTELLUNGEN_CALC_BUTTON As Integer = 409
Private Const BESTELLUNGEN_CALC_TEXTBOX As Integer = 410

Private objDocument As Word.Document

' Konstantwerte für die Datenverbindungen
Private Const strConnectionPrefix = "File Name="
Private Const strConnectionUDL = "BSP24_02.udl"
Private Const strBestellungenDatei = "Bestellungen.xml"
Private Const strBestellungenXSLT = "BSP24_02.xsl"

' Platzhalterzeichen für Mustervergleiche
' ANSI-92 statt dem alten ANSI-89 (*)
Private Const strWildCard = "%"
' Private Const strWildCard = "*"

Private bPlannedKundeMaintenance As Boolean
Private lngKundenSelectedRow As Long
Private strSolutionPath As String ' für die UDL und temp Dateien
Private var1 As Variant ' um Variants neu zu initialisieren
Private varKunden As Variant ' Liste der Kunden


Private Property Get ISmartDocument_ControlCaptionFromID( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object) As String

  Dim rngTarget As Word.Range

' Eine Beschriftung jedem Steuerelement zuweisen, das eine
' Beschriftung haben darf
Select Case LocaleID
  Case 1031 ' Deutsch
    Select Case ControlID
      Case SCHEMA_HELP
        ISmartDocument_ControlCaptionFromID = "Anweisungen"
      Case KUNDE_HELP
        ISmartDocument_ControlCaptionFromID = "Hilfe für die Kundenauswahl"
      Case KUNDE_SEPARATOR1
        ISmartDocument_ControlCaptionFromID = "Trennlinie"
      Case KUNDE_COMBO
        ISmartDocument_ControlCaptionFromID = "Einen Kunden auswählen"
      Case KUNDE_FIRMA_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Firma:"
      Case KUNDE_STRASSE_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Straße:"
      Case KUNDE_ORT_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Ort:"
      Case KUNDE_REGION_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Region:"
      Case KUNDE_PLZ_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "PLZ:"
      Case KUNDE_LAND_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Land:"
      Case KUNDE_KONTAKTPERSON_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Kontaktperson:"
      Case KUNDE_POSITION_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Position:"
      Case KUNDE_INSERT_BUTTON
        ISmartDocument_ControlCaptionFromID = "Kundendetails einfügen"
      Case BETREFF_HELP
        ISmartDocument_ControlCaptionFromID = "Hilfe für den Betreff"
      Case BETREFF_SEPARATOR1
        ISmartDocument_ControlCaptionFromID = "Trennlinie"
      Case BETREFF_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Betreff:"
      Case BETREFF_INSERT_BUTTON
        ISmartDocument_ControlCaptionFromID = "Betreff einfügen"
      Case BESTELLUNGEN_HELP
        ISmartDocument_ControlCaptionFromID = "Bestellungen-Auswahl"
      Case BESTELLUNGEN_SEPARATOR1
        ISmartDocument_ControlCaptionFromID = "Trennlinie"
      Case BESTELLUNGEN_KUNDE_CAPTION
        ISmartDocument_ControlCaptionFromID = _
          "Bestellungen für den folgenden Kunden-Code/Firma"
      Case BESTELLUNGEN_KUNDE_LABEL
        Set rngTarget = Target
        ISmartDocument_ControlCaptionFromID = _
          rngTarget.Document.Variables("Kunde").Value
        Set rngTarget = Nothing
      Case BESTELLUNGEN_OPTIONS
        ISmartDocument_ControlCaptionFromID = "Bestellungen-Optionen"
      Case BESTELLUNGEN_ZAHL_TEXTBOX
        ISmartDocument_ControlCaptionFromID = _
          "Anzahl:"
      Case BESTELLUNGEN_INSERT_BUTTON
        ISmartDocument_ControlCaptionFromID = "Bestellungen einfügen"
      Case BESTELLUNGEN_SEPARATOR2
        ISmartDocument_ControlCaptionFromID = "Trennlinie"
      Case BESTELLUNGEN_CALC_BUTTON
        ISmartDocument_ControlCaptionFromID = "Summe der markierten Zellen"
      Case BESTELLUNGEN_CALC_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Summe (nur durchgehend markierte Zellen):"
      Case Else
    End Select
  
  Case Else ' Englisch
    Select Case ControlID
      Case SCHEMA_HELP
        ISmartDocument_ControlCaptionFromID = "Instructions"
      Case KUNDE_HELP
        ISmartDocument_ControlCaptionFromID = "Customer selection Help"
      Case KUNDE_COMBO
        ISmartDocument_ControlCaptionFromID = "Select a Customer"
      Case KUNDE_SEPARATOR1
        ISmartDocument_ControlCaptionFromID = "Separator"
      Case KUNDE_FIRMA_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Customer name:"
      Case KUNDE_STRASSE_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Street:"
      Case KUNDE_ORT_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "City:"
      Case KUNDE_REGION_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Region:"
      Case KUNDE_PLZ_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Postcode:"
      Case KUNDE_LAND_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Country:"
      Case KUNDE_KONTAKTPERSON_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Contact person:"
      Case KUNDE_POSITION_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Job Title:"
      Case KUNDE_INSERT_BUTTON
        ISmartDocument_ControlCaptionFromID = "Insert Customer details"
      Case BETREFF_HELP
        ISmartDocument_ControlCaptionFromID = "Help for the Subject"
      Case BETREFF_SEPARATOR1
        ISmartDocument_ControlCaptionFromID = "Separator"
      Case BETREFF_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Subject: "
      Case BETREFF_INSERT_BUTTON
        ISmartDocument_ControlCaptionFromID = "Insert Subject"
      Case BESTELLUNGEN_HELP
        ISmartDocument_ControlCaptionFromID = "Order selection"
      Case BESTELLUNGEN_SEPARATOR1
        ISmartDocument_ControlCaptionFromID = "Separator"
      Case BESTELLUNGEN_KUNDE_CAPTION
        ISmartDocument_ControlCaptionFromID = _
          "Orders for the following customer code/name"
      Case BESTELLUNGEN_KUNDE_LABEL
        Set rngTarget = Target
        ISmartDocument_ControlCaptionFromID = _
          rngTarget.Document.Variables("Kunde").Value
        Set rngTarget = Nothing
      Case BESTELLUNGEN_OPTIONS
        ISmartDocument_ControlCaptionFromID = "Order options"
      Case BESTELLUNGEN_ZAHL_TEXTBOX
        ISmartDocument_ControlCaptionFromID = _
          "Number of orders to insert (for the Oldest and Newest Options):"
      Case BESTELLUNGEN_INSERT_BUTTON
        ISmartDocument_ControlCaptionFromID = "Insert orders"
      Case BESTELLUNGEN_SEPARATOR2
        ISmartDocument_ControlCaptionFromID = "Separator"
      Case BESTELLUNGEN_CALC_BUTTON
        ISmartDocument_ControlCaptionFromID = "Total selected cells"
      Case BESTELLUNGEN_CALC_TEXTBOX
        ISmartDocument_ControlCaptionFromID = "Total (only contiguous cells):"
      Case Else
    End Select

End Select

End Property

Private Property Get ISmartDocument_ControlCount( _
  ByVal XMLTypeName As String) As Long
' Anzahl der mit einem namespace#elementID assozierten
' Steuerelemente festlegen

  Select Case XMLTypeName
    Case SCHEMA
      ISmartDocument_ControlCount = 1
    Case KUNDE
      ISmartDocument_ControlCount = 12
    Case BETREFF
      ISmartDocument_ControlCount = 4
    Case BESTELLUNGEN
      ISmartDocument_ControlCount = 10
    Case Else
  End Select

End Property

Private Property Get ISmartDocument_ControlID( _
  ByVal XMLTypeName As String, _
  ByVal ControlIndex As Long) As Long
' Gibt einen eindeutigen numerischen Wert für jedes Steuerelement
' zurück. Ist der Typ beispielsweise
' http://www.KAP24Beispiel.com/BSP02#Kunde, wird eine Zahl
' zwischen 200 und 300 zurückgegeben.

  Select Case XMLTypeName
    Case SCHEMA
      ISmartDocument_ControlID = ControlIndex + 100
    Case KUNDE
      ISmartDocument_ControlID = ControlIndex + 200
    Case BETREFF
      ISmartDocument_ControlID = ControlIndex + 300
    Case BESTELLUNGEN
      ISmartDocument_ControlID = ControlIndex + 400
    Case Else
  End Select
End Property

Private Property Get ISmartDocument_ControlNameFromID( _
  ByVal ControlID As Long) As String
' Erstellt für jedes Steuerelement eine eindeutige ID
  
  ISmartDocument_ControlNameFromID = CStr(ControlID)
End Property

Private Property Get ISmartDocument_ControlTypeFromID( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long) As SmartTagLib.C_TYPE
' Gibt die Art des Steuerelements für jedes ControlID (Konstantwert) zurück

  Select Case ControlID
    Case KUNDE_COMBO
      ISmartDocument_ControlTypeFromID = C_TYPE_COMBO
    Case KUNDE_INSERT_BUTTON, _
         BETREFF_INSERT_BUTTON, _
         BESTELLUNGEN_INSERT_BUTTON, _
         BESTELLUNGEN_CALC_BUTTON
      ISmartDocument_ControlTypeFromID = C_TYPE_BUTTON
    Case SCHEMA_HELP, _
         KUNDE_HELP, _
         BETREFF_HELP, _
         BESTELLUNGEN_HELP
      ISmartDocument_ControlTypeFromID = C_TYPE_HELP
    Case BESTELLUNGEN_KUNDE_CAPTION, _
         BESTELLUNGEN_KUNDE_LABEL
      ISmartDocument_ControlTypeFromID = C_TYPE_LABEL
    Case BESTELLUNGEN_OPTIONS
      ISmartDocument_ControlTypeFromID = C_TYPE_RADIOGROUP
    Case KUNDE_SEPARATOR1, _
         BETREFF_SEPARATOR1, _
         BESTELLUNGEN_SEPARATOR1, _
         BESTELLUNGEN_SEPARATOR2
      ISmartDocument_ControlTypeFromID = C_TYPE_SEPARATOR
    Case KUNDE_FIRMA_TEXTBOX, _
         KUNDE_STRASSE_TEXTBOX, _
         KUNDE_ORT_TEXTBOX, _
         KUNDE_REGION_TEXTBOX, _
         KUNDE_PLZ_TEXTBOX, _
         KUNDE_LAND_TEXTBOX, _
         KUNDE_KONTAKTPERSON_TEXTBOX, _
         KUNDE_POSITION_TEXTBOX, _
         BETREFF_TEXTBOX, _
         BESTELLUNGEN_ZAHL_TEXTBOX, _
         BESTELLUNGEN_CALC_TEXTBOX
      ISmartDocument_ControlTypeFromID = C_TYPE_TEXTBOX
    Case Else
  End Select

End Property

' Die Ereignisse für die Steuerelemente. Da wir
' ein Interface implementieren, müssen sie alle
' in der Klasse vorhanden sein, auch wenn keine
' Steuerelemente dieser Art in der Lösung benutzt werden.
Private Sub ISmartDocument_ImageClick( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal Target As Object, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal LocaleID As Long, _
  ByVal XCoordinate As Long, _
  ByVal YCoordinate As Long)
' Keine Grafiken
End Sub

Private Sub ISmartDocument_InvokeControl( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal Target As Object, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal LocaleID As Long)
  
  On Error Resume Next

  ' Der Anwender darf die Vorlage nicht als Dokument verwenden
  If Target.Parent.Type = wdTypeTemplate Then
    Select Case LocaleID
      Case 1031 ' Deutsch
        MsgBox "Sie dürfen in der Lösung-Vorlage" & _
        " (.dot) keinen Text eingeben. Bitte davon ein neues" & _
        " Word-Dokument (.doc) erstellen.", vbOKOnly, "Word-Vorlage"
      Case Else ' Englisch
        MsgBox "You cannot enter text into the Template" & _
        " (.dot) of this solution. Please open the" & _
        " document as a Word document (.doc) type.", vbOKOnly, "Word Template"
    End Select
    Exit Sub
  End If
  
  Select Case ControlID
    Case KUNDE_INSERT_BUTTON
      Invoke_KUNDE_INSERT_BUTTON Target, LocaleID
    
    Case BETREFF_INSERT_BUTTON
      Invoke_BETREFF_INSERT_BUTTON Target, LocaleID
      
    Case BESTELLUNGEN_INSERT_BUTTON
      Invoke_BESTELLUNGEN_INSERT_BUTTON Target, LocaleID
    
    Case BESTELLUNGEN_CALC_BUTTON
      Invoke_BESTELLUNGEN_CALC_BUTTON Target, LocaleID
    
    Case Else
  End Select

End Sub

Private Sub Invoke_KUNDE_INSERT_BUTTON( _
  ByVal Target As Object, _
  ByVal LocaleID As Long)
  
  Dim objRecordset As ADODB.Recordset
  Dim objXMLNode As Word.XMLNode
  Dim rngTarget As Word.Range

  ' Target (als Objekt deklariert) ist ein Range-Objekt
  ' diese Zeile ermöglicht den Einsatz von Intellisense
  ' während der Code-Eingabe
  Set rngTarget = Target
  Set objXMLNode = rngTarget.XMLNodes(1)

  If objXMLNode.SmartTag.SmartTagActions(CStr(KUNDE_COMBO)).ListSelection = -1 Then
    Select Case LocaleID
      Case 1031 'Deutsch
        MsgBox "Bitte wählen Sie in der Liste einen Kundennamen aus.", vbOKOnly, "Kunde auswählen"
      Case Else 'Englisch
        MsgBox "Please select a customer name from the list.", vbOKOnly, "Select Customer"
    End Select
    Exit Sub
  End If
      
  If Trim$(rngTarget.Document.SelectSingleNode("//ns:Firma", "xmlns:ns='" & NAMESPACE & "'").Text) <> "" Then
    Select Case LocaleID
      Case 1031 'Deutsch
        If MsgBox("Im Dokument sind bereits Informationen zum Kunden " & _
                  " sowie seinen Bestellungen vorhanden." & _
                  " Möchten Sie alle Kundeninformationen " & _
                  " aus dem Dokument entfernen?", vbYesNo, "Kunde & Bestellungen überschreiben") = vbNo Then
          Exit Sub
        End If
      Case Else 'Englisch
        If MsgBox("Customer information and related order infomation" & _
                  " has already been inserted into the document." & _
                  " Would you like to overwrite the existing " & _
                  " customer and order information?", vbYesNo, "Overwrite customer & order info.") = vbNo Then
          Exit Sub
        End If
    End Select
  End If
    
  ' Bei der Aktualisierung der Kundendaten im Dokument
  ' wird der Fokus des Aufgabenbereichs geändert. Um
  ' dies zu verhindern, halten wir fest, ob die Daten
  ' im Dokument aktualisiert werden.
  bPlannedKundeMaintenance = True
  
  ' Kundeninformationen direkt aus den Steuerelementen einfügen,
  ' falls diese Daten enthalten
  SetNodeValueFromTextbox "//ns:Kunde/ns:Firma", objXMLNode, KUNDE_FIRMA_TEXTBOX
  SetNodeValueFromTextbox "//ns:Kunde/ns:Adresse/ns:Straße", objXMLNode, KUNDE_STRASSE_TEXTBOX
  SetNodeValueFromTextbox "//ns:Kunde/ns:Adresse/ns:Ort", objXMLNode, KUNDE_ORT_TEXTBOX
  SetNodeValueFromTextbox "//ns:Kunde/ns:Adresse/ns:Region", objXMLNode, KUNDE_REGION_TEXTBOX
  SetNodeValueFromTextbox "//ns:Kunde/ns:Adresse/ns:PLZ", objXMLNode, KUNDE_PLZ_TEXTBOX
  SetNodeValueFromTextbox "//ns:Kunde/ns:Adresse/ns:Land", objXMLNode, KUNDE_LAND_TEXTBOX
  SetNodeValueFromTextbox "//ns:Kunde/ns:Kontaktperson", objXMLNode, KUNDE_KONTAKTPERSON_TEXTBOX
  SetNodeValueFromTextbox "//ns:Kunde/ns:Position", objXMLNode, KUNDE_POSITION_TEXTBOX
  
 ' Felder in den Kundenelementen aktualisieren
  rngTarget.Document.SelectSingleNode("//ns:Kunde", "xmlns:ns='" & NAMESPACE & "'").Range.Fields.Update
      
  ' Den gegenwärtigen Kunde festhalten, um später seine Bestellungen nachzuschlagen
  rngTarget.Document.Variables("Kunden-Code").Delete
  rngTarget.Document.Variables("Kunde").Delete
  rngTarget.Document.Variables.Add Name:="Kunden-Code", Value:=CStr(varKunden(0, lngKundenSelectedRow - 1))
  rngTarget.Document.Variables.Add Name:="Kunde", Value:=CStr(varKunden(1, lngKundenSelectedRow - 1))
      
  ' Die gegenwärtig aufgelisteten Bestellungen löschen
  ClearBestellungen rngTarget.Document, False
      
  ' Falls der Betreff leer ist, diesen Knotenpunk anspringen;
  ' sonst zum Knotenpunkt Bestellungen gehen
  If Trim(rngTarget.Document.SelectSingleNode("//ns:Betreff", "xmlns:ns='" & NAMESPACE & "'").Range.Text) = "" Then
    rngTarget.Document.SelectSingleNode("//ns:Betreff", "xmlns:ns='" & NAMESPACE & "'").Range.Select
  Else
    rngTarget.Document.SelectSingleNode("//ns:Bestellungen", "xmlns:ns='" & NAMESPACE & "'").Range.Select
  End If
  
  bPlannedKundeMaintenance = False
  rngTarget.Document.SmartDocument.RefreshPane

  Set rngTarget = Nothing
  Set objXMLNode = Nothing

End Sub

Private Sub Invoke_BETREFF_INSERT_BUTTON( _
  ByVal Target As Object, _
  ByVal LocaleID As Long)
  
  Dim objXMLNode As Word.XMLNode
  Dim rngTarget As Word.Range

  Set rngTarget = Target
  Set objXMLNode = rngTarget.XMLNodes(1)

  ' In diesem Fall wird der Kunde nicht nachgefragt ...
  SetNodeValueFromTextbox "//ns:Betreff", objXMLNode, BETREFF_TEXTBOX
  rngTarget.Document.BuiltInDocumentProperties("Subject") = _
    objXMLNode.SmartTag.SmartTagActions(CStr(BETREFF_TEXTBOX)).TextboxText & ""
  rngTarget.Document.SelectSingleNode("//ns:Bestellungen", "xmlns:ns='" & NAMESPACE & "'").Range.Select
    
  rngTarget.Document.SmartDocument.RefreshPane

  Set rngTarget = Nothing
  Set objXMLNode = Nothing
 
End Sub

Private Sub Invoke_BESTELLUNGEN_INSERT_BUTTON( _
  ByVal Target As Object, _
  ByVal LocaleID As Long)
  
  Dim intBestellungenZahl As Integer
  Dim objRecordset As ADODB.Recordset
  Dim objXMLNode As Word.XMLNode
  Dim rngTarget As Word.Range
  Dim strBestellungenZahl As String
  Dim strPad1 As String
  Dim strPad2 As String
  Dim strSequence As String
  Dim strSQL As String
  Dim strTOP As String

  Set rngTarget = Target
  Set objXMLNode = rngTarget.XMLNodes(1)

  Dim intOption As Integer
  intOption = objXMLNode.SmartTag.SmartTagActions(CStr(BESTELLUNGEN_OPTIONS)).RadioGroupSelection
  If intOption = -1 Then
    Select Case LocaleID
      Case 1031 'Deutsch
        MsgBox "Bitte wählen Sie eine der Optionen aus", vbOK, _
               "Bestellungen einfügen"
      Case Else 'Englisch
        MsgBox "Please select one of the option buttons", vbOK, _
               "Insert orders"
    End Select
    Exit Sub
  End If
  ' Warnung an den Anwender, dass sich Bestellungen
  ' im Dokument befinden.
  If Trim(rngTarget.Document.SelectSingleNode("//ns:Bestellungen", _
       "xmlns:ns='" & NAMESPACE & "'").Text) <> "" Then
    Select Case LocaleID
      Case 1031 'Deutsch
        If MsgBox("Eine Liste der Bestellungen befindet sich bereits im" & _
                  " Dokument. Wollen Sie diese ersetzen?", vbYesNo, _
                  "Bestellungen einfügen") = vbNo Then
           Exit Sub
        End If
       Case Else 'Englisch
        If MsgBox("A list of orders has already been inserted." & _
                  "Do you want to overwrite it?", vbYesNo, _
                  "Insert orders") = vbNo Then
          Exit Sub
        End If
    End Select
  End If
  
  'Auswahl der Optionsschaltfläche
  Select Case intOption
    Case 1 ' Keine - die Liste entfernen und ein Leerzeichen eingeben, fertig
      ClearBestellungen rngTarget.Document, True
      Exit Sub
    Case Else ' Sicherstellen, dass ein Kunde vorhanden ist
      If lngKundenSelectedRow = -1 Then
        Select Case LocaleID
          Case 1031 'Deutsch
            MsgBox "Ein Kunde muss ausgewählt werden, bevor Sie" & _
                   " Bestellungen einfügen können", vbOKOnly, "Bestellungen einfügen"
          Case Else 'Englisch
            MsgBox "You must select a customer before you can insert" & _
                   " order records", vbOKOnly, "Insert orders"
        End Select
        Exit Sub
      End If
  End Select
  Select Case intOption
    Case 3, 4 ' Älteste/Neueste wurde gewählt.
              ' Die Anzahl der erwünschten Datensätze prüfen.
      intBestellungenZahl = -1
      strBestellungenZahl = _
        objXMLNode.SmartTag.SmartTagActions(CStr(BESTELLUNGEN_ZAHL_TEXTBOX)).TextboxText
      If Trim(strBestellungenZahl) = "" Then
        intBestellungenZahl = 1
      Else
        If IsNumeric(strBestellungenZahl) Then
          ' Der Maximalwert 100 ist willkürlich
          If CDbl(strBestellungenZahl) >= 1 And CDbl(strBestellungenZahl) <= 100 Then
            intBestellungenZahl = CInt(strBestellungenZahl)
          End If
        End If
      End If
      If intBestellungenZahl = -1 Then
        Select Case LocaleID
          Case 1031 'Deutsch
            MsgBox "Bitte geben Sie eine Zahl zwischen 1 und 100 für die Anzahl der Datensätze ein.", _
              vbOKOnly, "Bestellungen einfügen"
            Exit Sub
          Case Else 'Englisch
            MsgBox "Please enter a record count between 1 and 100", vbOKOnly, "Insert orders"
            Exit Sub
        End Select
        Exit Sub
      End If
      ' SQL-Code-Fragmente generieren. Sie basieren auf
      ' die Anzahl der Datensätze + gewählte Option
      strTOP = "TOP " & CStr(intBestellungenZahl) & " "
      If intOption = 3 Then
        strSequence = "ASC"
      Else
        strSequence = "DESC"
      End If
    Case Else '"Alle" wird angenommen
      strTOP = ""
      strSequence = "ASC"
  End Select
   
  ' Die Datensätze aus der Datenbank holen
  Set objRecordset = New ADODB.Recordset
strSQL = _
    " SELECT " & strTOP & "be.[Bestell-Nr]," & _
    " format(be.Bestelldatum,'YYYYMMDD') As `sortable`," & _
    " format(be.Bestelldatum,'DD MMM YYYY') As `Bestelldatum`," & _
    " format(be.Lieferdatum,'DD MMM YYYY') As `Lieferdatum`," & _
    " format(be.Versanddatum,'DD MMM YYYY') As `Versanddatum`," & _
    " ve.Firma As `VersandÜber`," & _
    " iif(isnull(be.Frachtkosten),'0.00'," & _
    " format(be.Frachtkosten,'#.00')) As `Frachtkosten`" & _
    " FROM Bestellungen be INNER JOIN Versandfirmen ve" & _
    " ON be.VersandÜber = ve.[Firmen-Nr]" & _
    " WHERE be.[Kunden-Code] = '" & _
    rngTarget.Document.Variables("Kunden-Code").Value & "'" & _
    " ORDER BY 2 " & strSequence
  objRecordset.Open _
    Source:=strSQL, _
    ActiveConnection:=strConnectionPrefix & strSolutionPath & strConnectionUDL, _
    CursorType:=adOpenForwardOnly
  ' Die vorhandene Bestellungen.xml-Datei löschen
  ' und via ADO das Recordset in eine neue serialisieren
  On Error Resume Next
  Kill strSolutionPath & strBestellungenDatei
  objRecordset.Save strSolutionPath & strBestellungenDatei, adPersistXML
  objRecordset.Close
  Set objRecordset = Nothing
  
  ' Eine INCLUDETEXT-Feldfunktion in das Element "Bestellungen" einfügen,
  ' um die XML-Datei in Bestellungen.xml zu transformieren. Die Feldfunktion
  ' anschließend auflösen.
  strPad1 = Replace(strSolutionPath & strBestellungenDatei, "\", "\\")
  strPad2 = Replace(strSolutionPath & strBestellungenXSLT, "\", "\\")
  ClearBestellungen rngTarget.Document, False
  rngTarget.Fields.Add _
    Range:=rngTarget, _
    Type:=wdFieldEmpty, _
    Text:="INCLUDETEXT """ & strPad1 & """ \t """ & strPad2 & """", _
    preserveformatting:=False
  rngTarget.Fields.Unlink
  Set rngTarget = Nothing
  Set objXMLNode = Nothing

End Sub

Private Sub Invoke_BESTELLUNGEN_CALC_BUTTON( _
  ByVal Target As Object, _
  ByVal LocaleID As Long)
  
' Den numerischen Inhalt aller durchgehenden
' markierten Zellen summieren (Zellen mit Text oder
' mehr als eine Zahl werden ausgelassen)

  Dim dblTotal As Double
  Dim objCell As Word.Cell
  Dim objXMLNode As Word.XMLNode
  Dim rngTarget As Word.Range
  Dim strTextonly

  dblTotal = 0#
  For Each objCell In Target.Application.Selection.Cells
    strTextonly = Left(objCell.Range.Text, Len(objCell.Range.Text) - 1)
    If IsNumeric(strTextonly) Then
      dblTotal = dblTotal + CDbl(strTextonly)
    End If
  Next
  SetTextboxText Target, BESTELLUNGEN_CALC_TEXTBOX, CStr(dblTotal)

End Sub

Private Sub ISmartDocument_OnCheckboxChange( _
  ByVal ControlID As Long, _
  ByVal Target As Object, _
  ByVal Checked As Boolean)
' Keine Kontrollkästchen

End Sub

Private Sub ISmartDocument_OnListOrComboSelectChange( _
  ByVal ControlID As Long, _
  ByVal Target As Object, _
  ByVal Selected As Long, _
  ByVal Value As String)

  Select Case ControlID
    Case KUNDE_COMBO
      ' Alle Textfelder des Kunde-Abschnitts im Aufgabenbereich mit Daten füllen
      SetTextboxText Target, KUNDE_FIRMA_TEXTBOX, CStr(varKunden(2, Selected - 1))
      SetTextboxText Target, KUNDE_STRASSE_TEXTBOX, CStr(varKunden(3, Selected - 1))
      SetTextboxText Target, KUNDE_ORT_TEXTBOX, CStr(varKunden(4, Selected - 1))
      SetTextboxText Target, KUNDE_REGION_TEXTBOX, CStr(varKunden(5, Selected - 1))
      SetTextboxText Target, KUNDE_PLZ_TEXTBOX, CStr(varKunden(6, Selected - 1))
      SetTextboxText Target, KUNDE_LAND_TEXTBOX, CStr(varKunden(7, Selected - 1))
      SetTextboxText Target, KUNDE_KONTAKTPERSON_TEXTBOX, CStr(varKunden(8, Selected - 1))
      SetTextboxText Target, KUNDE_POSITION_TEXTBOX, CStr(varKunden(9, Selected - 1))
      lngKundenSelectedRow = Selected
    Case Else
  End Select
  
End Sub

Private Sub ISmartDocument_OnPaneUpdateComplete( _
  ByVal Document As Object)

  Dim objDocument As Word.Document
  Set objDocument = Document
  With objDocument
  
    On Error Resume Next
    ' Any existing value will not be overwritten, but this makes
    ' sure there is a value
    .CustomDocumentProperties.Add Name:="ShowXMLMarkup", Value:="off"
    On Error GoTo 0
    Select Case .CustomDocumentProperties("ShowXMLMarkup").Value
      Case "off"
        .ActiveWindow.View.ShowXMLMarkup = False
      Case "on"
        .ActiveWindow.View.ShowXMLMarkup = True
      Case Else
    End Select
  End With
  Set objDocument = Nothing
End Sub

Private Sub ISmartDocument_OnRadioGroupSelectChange( _
  ByVal ControlID As Long, _
  ByVal Target As Object, _
  ByVal Selected As Long, _
  ByVal Value As String)
' Idealerweise würden wir das Textfeld für die Anzahl
' der Datensätze je nach Auswahl aus-/oder einblenden.
' Das ist jedoch nicht einfach. Außerdem wird keine
' LocaleID (Sprachinformationen) übergeben, was mehr-
' sprachige Auskünfte erschweren würde.

  Select Case ControlID
    Case BESTELLUNGEN_OPTIONS
    Case Else
  End Select
End Sub

Private Sub ISmartDocument_OnTextboxContentChange( _
  ByVal ControlID As Long, _
  ByVal Target As Object, _
  ByVal Value As String)

End Sub

Private Sub ISmartDocument_PopulateActiveXProps( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties, _
  ByVal ActiveXPropBag As SmartTagLib.ISmartDocProperties)
' Keine benutzerdefinierten ActiveX-Steuerelemente
End Sub

Private Sub ISmartDocument_PopulateCheckbox( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties, _
  Checked As Boolean)
' Keine Kontrollkästchen
End Sub

Private Sub ISmartDocument_PopulateDocumentFragment(ByVal ControlID As Long, ByVal ApplicationName As String, ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object, ByVal Props As SmartTagLib.ISmartDocProperties, DocumentFragment As String)
' Keine Dokument-Fragmente
End Sub

' Hilfe-Texte
Private Sub ISmartDocument_PopulateHelpContent( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties, _
  Content As String)

  Select Case LocaleID
    Case 1031 ' Deutsch
      Select Case ControlID
        Case SCHEMA_HELP
          Content = "<html><body><ol><li>" & _
          "Einen Kunden ausw&auml;hlen. Wo n&ouml;tig, die Einzelheiten &auml;ndern." & _
          " Anschlie&szlig;end 'Kundendetails einf&uuml;gen' klicken, um die Informationen einzuf&uuml;gen.</li>" & _
          "<li>Den Betreff eingeben, dann die Schaltfl&auml;che bet&auml;tigen, um ihn einzuf&uuml;gen.</li>" & _
          "<li>Die Anzahl Bestellungendatens&auml;tze festlegen: keine, alle," & _
          " die &auml;ltesten oder die neuesten (nach Bestellungsdatum).</li>" & _
          "<li>Den restlichen Inhalt direkt in das Dokument eingeben und formatieren: " & _
          "Anrede, Flie&szlig;text, usw." & _
          "</li></ol></body></html>"
        Case KUNDE_HELP
          Content = "<html><body><p>" & _
          "Aus der Liste den Kunden-Code/Firmenname ausw&auml;hlen. " & _
          "Wo n&ouml;tig, die Daten anpassen. Anschlie&szlig;end auf die Schaltfl&auml;che" & _
          " Kundendetails einf&uuml;gen klicken, um die Daten in das Dokument zu schreiben." & _
          " Achten Sie vor allem auf fehlende Informationen, wie Stra&szlig;e oder " & _
          " Land und erg&auml;nzen Sie diese im Aufgabenbereich.</p></body></html>"
        Case BETREFF_HELP
          Content = "<html><body><p>" & "Geben Sie f&uuml;r den Brief einen Betreff ein, " & _
            "dann bet&auml;tigen Sie die Schaltfl&auml;che." & "</p></body></html>"
        Case BESTELLUNGEN_HELP
          Content = "<html><body><p>Sie k&ouml;nnen f&uuml;r diesen Kunden keine, alle," & _
                    " die &auml;testen oder die neuesten Bestellungen einf&uuml;gen." & _
                    " Bei Auswahl der &auml;testen oder die neuesten Bestellungen " & _
                    " bitte die Anzahl Datens&auml;tze eingeben, sonst wird 1 (eins) angenommen." & _
                    "</p></body></html>"
        Case Else
      End Select
    
    Case Else ' Englisch
      Select Case ControlID
        Case SCHEMA_HELP
          Content = "<html><body><p>" & _
          "First, select a Customer, modify the details as required, and" & _
          " click the button to insert the details</p>" & _
          "<p>Then, fill in the Subject and click the button.</p>" & _
          "<p>Then, select the Order records you want - none, all, or" & _
          " the oldest or newest bsed on the order date.</p>" & _
          "<p>Everything else - Greeting, Salutation, body text, " & _
          "is free form text that you should type as required." & _
          "</p></body></html>"
        Case KUNDE_HELP
          Content = "<html><body><p>" & _
          "Select a Customer Code/Company Name" & _
          " from the list. Modify any data as needed, then click" & _
          " the Insert button to include it in the document." & _
          " In particular, if any address details such as the destination" & _
          " country are missing, type them into the boxes in the Action pane.</p></body></html>"
        Case BETREFF_HELP
          Content = "<html><body><p>" & _
            "Type a subject for the letter, then click the button." & _
            "</p></body></html>"
        Case BESTELLUNGEN_HELP
          Content = "<html><body><p>You can insert none, all, the" & _
                    " oldest or newest orders for this customer." & _
                    " If you select Oldest or Newest, enter the " & _
                    " number of orders you want to list. The default is 1." & _
                    "</p></body></html>"
        Case Else
      End Select
  End Select

End Sub

Private Sub ISmartDocument_PopulateImage( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties, _
  ImageSrc As String)
' Keine Grafiken
End Sub

Private Sub ISmartDocument_PopulateListOrComboContent( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties, _
  List() As String, _
  Count As Long, _
  InitialSelected As Long)
  
  Dim lngRowCount As Long
  Dim lngIndex As Long

  Dim objRecordset As ADODB.Recordset
 
  On Error GoTo ErrorHandler
  Select Case ControlID
    Case KUNDE_COMBO
      If Not bPlannedKundeMaintenance Then
        Set objRecordset = New ADODB.Recordset
        ' Die Kundendaten können getrennt gelesen werden.
        ' Wenn man versucht, die Daten in ein Datenfeld des Typs
        ' Variant zu lesen, soll das Vorkommen von Null-Werten
        ' geprüft werden. Sonst kann ADO unerwartete Ergebnisse liefern.
        
        objRecordset.Open _
          Source:=" SELECT [Kunden-Code]," & _
                  "[Kunden-Code] + ': ' + Firma as `X`," & _
                  " Firma, iif(isnull([Straße]),'',[Straße])," & _
                  " iif(isnull(Ort),'',Ort)," & _
                  " iif(isnull(Region),'',Region)," & _
                  " iif(isnull(PLZ),'',PLZ)," & _
                  " iif(isnull(Land),'',Land)," & _
                  " iif(isnull(Kontaktperson),'',Kontaktperson)," & _
                  " iif(isnull([Position]),'',[Position])" & _
                  " FROM Kunden" & _
                  " ORDER BY 1", _
          ActiveConnection:=strConnectionPrefix & strSolutionPath & strConnectionUDL, _
          CursorType:=adOpenForwardOnly
        If objRecordset.EOF And objRecordset.BOF Then
           ReDim List(1 To 1)
           Select Case LocaleID
             Case 1031 'Deutsch
               List(1) = "Keine Kundendatensätze gefunden"
             Case Else 'Englisch
               List(1) = "No Customer records found"
           End Select
        Else
          varKunden = var1
          varKunden = objRecordset.GetRows
          Count = UBound(varKunden, 2) + 1
          ReDim List(1 To Count) As String
          For lngIndex = 1 To Count
            List(lngIndex) = varKunden(1, lngIndex - 1)
          Next
        End If
        objRecordset.Close
        Set objRecordset = Nothing
        InitialSelected = -1
        Props.Write Key:="IsEditable", Value:="false"
        Props.Write Key:="ControlOnSameLine", Value:="False"
        Props.Write Key:="W", Value:="200"
      End If
    Case Else
  End Select

Finally:
Exit Sub

ErrorHandler:
  MsgBox Err.Description
  Resume Finally
End Sub

Private Sub ISmartDocument_PopulateOther( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties)

End Sub

Private Sub ISmartDocument_PopulateRadioGroup( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties, _
  List() As String, _
  Count As Long, _
  InitialSelected As Long)

  Dim intIndex As Integer
  Select Case ControlID
    Case BESTELLUNGEN_OPTIONS
      Count = 4
      ReDim List(1 To Count) As String
      Select Case LocaleID
        Case 1031 ' Deutsch
          List(1) = "Keine"
          List(2) = "Alles"
          List(3) = "Älteste"
          List(4) = "Neueste"
          InitialSelected = -1
        Case Else ' Englisch
          List(1) = "None"
          List(2) = "All"
          List(3) = "Oldest"
          List(4) = "Newest"
          InitialSelected = -1
      End Select
    Case Else
  End Select
End Sub

Private Sub ISmartDocument_PopulateTextboxContent( _
  ByVal ControlID As Long, _
  ByVal ApplicationName As String, _
  ByVal LocaleID As Long, _
  ByVal Text As String, _
  ByVal Xml As String, _
  ByVal Target As Object, _
  ByVal Props As SmartTagLib.ISmartDocProperties, _
  Value As String)

  Select Case ControlID
    Case KUNDE_FIRMA_TEXTBOX, _
         KUNDE_STRASSE_TEXTBOX, _
         KUNDE_ORT_TEXTBOX, _
         KUNDE_REGION_TEXTBOX, _
         KUNDE_PLZ_TEXTBOX, _
         KUNDE_LAND_TEXTBOX, _
         KUNDE_KONTAKTPERSON_TEXTBOX, _
         KUNDE_POSITION_TEXTBOX
      Props.Write Key:="ControlOnSameLine", Value:="False"
      Props.Write Key:="W", Value:="150"
    Case BESTELLUNGEN_ZAHL_TEXTBOX
      Props.Write Key:="ControlOnSameLine", Value:="False"
      Props.Write Key:="W", Value:="40"
    Case BESTELLUNGEN_CALC_TEXTBOX
      Props.Write Key:="ControlOnSameLine", Value:="False"
      Props.Write Key:="W", Value:="150"
    Case BETREFF_TEXTBOX
      Value = Text
      Props.Write Key:="ControlOnSameLine", Value:="False"
      Props.Write Key:="W", Value:="150"
    Case Else
  End Select

End Sub

Private Sub ISmartDocument_SmartDocInitialize( _
  ByVal ApplicationName As String, _
  ByVal Document As Object, _
  ByVal SolutionPath As String, _
  ByVal SolutionRegKeyRoot As String)

' Schaltet die Fehlermeldung aus, falls kein Kunde-Element vorhanden ist
On Error Resume Next

  ' Pfadangabe zu den UDL- sowie Temp-Dateien
  strSolutionPath = SolutionPath
  Set objDocument = Document
  With objDocument
    .SelectSingleNode("//ns:Kunde", "xmlns:ns='" & NAMESPACE & "'").Range.Select
    .Variables.Add Name:="Kunden-Code", Value:=" "
    .Variables.Add Name:="Kunde", Value:=" "
'''    .ActiveWindow.View.ShowXMLMarkup = False
  End With
  Set objDocument = Nothing
  varKunden = var1
  bPlannedKundeMaintenance = False
End Sub


Private Property Get ISmartDocument_SmartDocXmlTypeCaption( _
  ByVal XMLTypeID As Long, _
  ByVal LocaleID As Long) As String

  Select Case LocaleID
    Case 1031 ' Deutschf
      Select Case XMLTypeID
        Case SCHEMA_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Allgemeine Hilfe zum Dokument"
        Case KUNDE_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Hilfe für das Kunde-Element"
        Case BETREFF_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Hilfe für das Betreff-Element "
        Case BESTELLUNGEN_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Hilfe für das Bestellungen-Element"
        Case Else
      End Select
  
    Case Else ' Englisch - in this case the element names are in German in the Schema
              '            so it is probably best to use the German terms
      Select Case XMLTypeID
        Case SCHEMA_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Help with the document"
        Case KUNDE_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Help with the <Kunde> element"
        Case BETREFF_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Help with the <Betreff> element "
        Case BESTELLUNGEN_ID
          ISmartDocument_SmartDocXmlTypeCaption = "Help with the <Bestellungen> element"
        Case Else
      End Select
  End Select

End Property

Private Property Get ISmartDocument_SmartDocXmlTypeCount() As Long
  'Gibt die Anzahl namespace#element_id zurück
  ISmartDocument_SmartDocXmlTypeCount = NUM_TYPES

End Property


Private Property Get ISmartDocument_SmartDocXmlTypeName( _
  ByVal XMLTypeID As Long) As String
' Gibt die namespace#element_ID für eine numerische ID zurück

  Select Case XMLTypeID
    Case SCHEMA_ID
      ISmartDocument_SmartDocXmlTypeName = SCHEMA
    Case KUNDE_ID
      ISmartDocument_SmartDocXmlTypeName = KUNDE
    Case BETREFF_ID
      ISmartDocument_SmartDocXmlTypeName = BETREFF
    Case BESTELLUNGEN_ID
      ISmartDocument_SmartDocXmlTypeName = BESTELLUNGEN
    Case Else
  End Select

End Property

Private Sub ClearBestellungen( _
  ByRef objDocument As Word.Document, _
  bLeaveSpace As Boolean)

  Dim rngNode As Word.Range
  Dim tbl As Word.Table
  On Error Resume Next
  Set rngNode = _
    objDocument.SelectSingleNode( _
      "//ns:Bestellungen", _
      "xmlns:ns='" & NAMESPACE & "'" _
      ).Range
  For Each tbl In rngNode.Tables
    tbl.Delete
  Next
  If bLeaveSpace Then
    rngNode.Text = " "
  Else
    rngNode.Text = ""
  End If
  Set rngNode = Nothing

End Sub
Private Sub SetNodeValue( _
  strXPath As String, _
  strValue As String, _
  ByRef objDocument As Word.Document)
' Den Inhalt eines Knotenpunkts durch die XPath-Angaben
' in strXPath festlegen. Das Namensraumpräfix "ns:" muss
' immer angegeben werden.

  Dim rngNode As Word.Range

  On Error Resume Next
  Set rngNode = _
    objDocument.SelectSingleNode( _
      strXPath, _
      "xmlns:ns='" & NAMESPACE & "'" _
      ).Range
  rngNode.Text = strValue
  Set rngNode = Nothing

End Sub

Private Sub SetNodeValueFromTextbox( _
  strXPath As String, _
  objXMLNode As Word.XMLNode, _
  intControlID As Integer)
'Legt den Wert des durch XPath bestimmten Knotenpunkts fest.

On Error GoTo 0
  SetNodeValue _
    strXPath, _
    objXMLNode.SmartTag.SmartTagActions(CStr(intControlID)).TextboxText, _
    objXMLNode.Range.Document

End Sub


Private Sub SetTextboxText( _
  ByRef Target As Object, _
  ByRef ControlID As Integer, _
  ByRef strText As String)

  Dim objXMLNode As Word.XMLNode
  
  Set objXMLNode = Target.XMLNodes(1)
  objXMLNode.SmartTag.SmartTagActions(CStr(ControlID)).TextboxText = strText
  Set objXMLNode = Nothing
End Sub
