Neuigkeiten:

Ist euer Problem gelöst, dann bitte den Knopf "Thema gelöst" drücken!

Mobiles Hauptmenü

Textmarke mit combobox füllen?

Begonnen von silentwolf, Dezember 15, 2011, 08:44:19

⏪ vorheriges - nächstes ⏩

silentwolf

Na ja da seit Ihr nicht alleine :)

Hier ist der Code



Private Sub cmdODoc_Click()

Dim appword As Word.Application
Dim doc As Word.Document
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strTemplatePath As String
Dim strTemplateName As String
Dim strTemplateNameAndPath As String

Dim strRecipientName As String
Dim strRecipientAddress As String
Dim strRecipientTown As String
Dim strRecipientZip As String
Dim strSalution As String
Dim strBillNumber As String

Dim strTitle As String
Dim strPrompt As String

Dim lngBillNumber As Long
Dim lngSalution As Long
Dim lngContactID As Long

Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File

    lngContactID = Nz(Me![KD_ID])
    If lngContactID = 0 Then
        strPrompt = "Kein Kontakt selektiert"
        strTitle = "Problem"
        MsgBox strPrompt, vbOKOnly + vbExclamation, strTitle


    Else

        strRecipientName = Nz(Me![KD_Firma])
        strRecipientAddress = Nz(Me![KD_StrasseNr])
        strRecipientTown = Nz(Me![KD_Ort])
        strRecipientZip = Nz(Me![KD_PLZ])

        lngBillNumber = Nz(Me![KD_PLZ])
        lngSalution = Nz(Me![KD_An_Id])


    End If

    Set appword = CreateObject("Word.Application")

    ' Get the default user Template path from the Word Options dialog (it is still available in code, _
      though it has disappearend from the Word 2007 interface)

    strTemplatePath = CurrentProject.Path

    strTemplateName = "RVorlage.dotx"

    strTemplateNameAndPath = strTemplatePath & "\" & strTemplateName

    If Dir(strTemplateNameAndPath) = "" Then

        MsgBox "Can't locate template file, " & strTemplateName & ",  in folder " & strTemplatePath, vbCritical, "Template Not Found"
        appword.Quit

        GoTo ErrorHandlerExit

    End If

    Set doc = appword.Documents.Add(strTemplateNameAndPath)

    'Write information to Word bookmarks in the document:

    With doc
        .Bookmarks("Adresse").Range.Text = strRecipientAddress
        .Bookmarks("Anrede").Range.Text = lngSalution
        .Bookmarks("KDNummer").Range.Text = lngContactID
        .Bookmarks("Name").Range.Text = strRecipientName
        .Bookmarks("Ort").Range.Text = strRecipientZip
        .Bookmarks("RNummer").Range.Text = strBillNumber
        .Bookmarks("ZZ").Range.Text = Format(Date, "Long date")

        .Goto what:=wdGoToBookmark, Name:="LetterText"

        strPrompt = "Ready to enter letter text"
        strTitle = "Access data imported"
        MsgBox strPrompt, vbOKOnly, strTitle
        appword.Visible = True
        appword.Activate

    End With
ErrorHandlerExit:
    Set appword = Nothing
    Exit Sub

End Sub



Klaus es ist mir ja eh klar das es so funktionieren muss wie Du sagst nur funktioniert es nicht.

Hab im Code [KD_An_Id] mit meinem textfeld ausgewechselt...txtAnrede
aber auch leder ohne erfolg


wo oder besser wie muss den der Code geändert werden damit ich nun das textfeld ansteuere?

Danke sehr!!!


MzKlMu

Hallo,
wenn Du einen Text willst, darfst Du keine Zahl deklarieren. Ändere mal wie folgt:

Dim strSalution As String
.
.
strSalution = Nz(Me!NameKombi.Column(1),"")
Gruß Klaus

silentwolf

Hallo Klaus,
danke... irgendwas stimmt leider noch nicht aber ich hab jetzt leider keine Zeit mehr muss weg..
Bedanke mich aber sehr sehr herzlich für Deine Hilfe.
Muss es mir später noch besser anschauen.


Danke

A