RE: Mail Merge lấy dữ liệu từ file Access
phamngocsang > 14-12-15, 07:51 PM
nhờ các Anh (Chị) giúp em xem code này có vấn đề không ạ:
nó báo lỗi hoài.
CODE:
Private Sub btmPrintToTrinh_Click()
    Dim this_path As String
    Dim this_db As String
    Dim STT As Integer
    this_path = Application.CurrentProject.Path & "\"
    this_db = this_path & Application.CurrentProject.name
    STT = Me.txtID.Value
    Dim word_app As Word.Application
    Dim word_doc As Word.Document
    Set word_app = CreateObject("Word.Application")
    Set word_doc = word_app.Documents.Open(this_path & "TTrGPXD.dot")
    word_app.Visible = True
    
    If word_doc.MailMerge.State <> wdMainAndDataSource Then
        word_doc.MailMerge.OpenDataSource this_db, , , True, True, , , , , , , , "SELECT * [tblDatabase] ID='STT'"
        word_doc.MailMerge.Destination = wdSendToNewDocument
        word_doc.MailMerge.Execute
    End If
End Sub
em cảm ơn nhiều !!!