Feldinhalte aus Formularen auslesen

Home-›Foren-›Outlook-›Outlook VBA-›Feldinhalte aus Formularen auslesen

1 Antwort anzeigen (von insgesamt 1)
  • Autor
    Beitrag
  • #40284
    Unbekannt
    Teilnehmer

      Also ich habe folgendes Problem, ich habe ein eigenes Formular erstellt und möchte gern bestimmte Felder in eine Word-Datei einfügen und sie anschlißend ausdrucken.
      Mein VBA-Code dazu sieht so aus:

      Sub cmdPrint_Click()
      Set oWordApp = CreateObject(\”Word.Application\”)
      If oWordApp Is Nothing Then
      MsgBox \”Couldn\’t start Word.\”
      Else
      Dim oWordApp
      Dim oWordDoc
      Dim bolPrintBackground
      Dim objFeld
      Dim objItem

      \’ Öffnen eines neuen Dokuments
      Set oDoc = oWordApp.Documents.Add(\”C:\\MyForm.dot\”)

      strMyField = Item.UserProperties.Find(\”_RecipientControl1\”)
      oDoc.FormFields(\”Text1\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox13\”) \’
      oDoc.FormFields(\”Text2\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox21\”)
      oDoc.FormFields(\”Text3\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox22\”) \’
      oDoc.FormFields(\”Text4\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox23\”) \’
      oDoc.FormFields(\”Text5\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox24\”) \’
      oDoc.FormFields(\”Text6\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox25\”) \’
      oDoc.FormFields(\”Text7\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”ComboBox3\”) \’
      oDoc.FormFields(\”Text8\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox10\”) \’
      oDoc.FormFields(\”Text9\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox11\”) \’
      oDoc.FormFields(\”Text10\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox12\”) \’
      oDoc.FormFields(\”Text11\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox15\”) \’
      oDoc.FormFields(\”Text12\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox14\”)
      oDoc.FormFields(\”Text13\”).Result = strMyField

      strMyField = Item.UserProperties.Find(\”TextBox17\”)
      oDoc.FormFields(\”Text14\”).Result = strMyField

      bolPrintBackground = oWordApp.Options.PrintBackground

      oWordApp.Options.PrintBackground = False

      oDoc.PrintOut

      oWordApp.Options.PrintBackground = bolPrintBackground

      Const wdDoNotSaveChanges = 0
      oDoc.Close wdDoNotSaveChanges

      oWordApp.Quit

      Set oDoc = Nothing
      Set oWordApp = Nothing
      End If
      End Sub

      Leider kommt schon beim ersten Wert den ich auslesen will ein Fehler und zwar das die Objektvariable strMyField nicht gesetzt ist. Setze ich sie allerdings kommt ebenfalls ein Fehler.
      Kann mir jemand sagen was an meinem Code falsch ist oder mir eventuell eine andere Möglichkeit mitteilen

      Vielen Dank im Vorraus

      Gonkster

    1 Antwort anzeigen (von insgesamt 1)

    -