在导出数据后关闭Word文档时,Access数据库关闭

时间:2018-07-18 01:44:59

标签: ms-word access-vba ms-access-2013

我有一个存储客户工作数据的数据库。此数据还用于通过导出到现有Word文档为客户打印证书。该数据库相当老,可以在Office 2003上正常工作。升级到最新的Office 365后,我现在遇到一个问题,即在将数据导出到Word之后,如果没有Access也无法关闭,则无法关闭Word。然后,我必须重新打开Access才能继续使用数据库。希望有人知道如何阻止这种情况的发生。 单击表单中的按钮即可将数据导出到Word,下面列出了运行的VBA代码。 (我没有创建代码或数据库) 预先感谢

Private Sub btnPrintCert_Click()
On Error GoTo Err_btnPrintCert_Click
    Dim strSQL As String
    Dim RetVal As Double
    Dim txtWordPath As String
    Dim txtDocPath As String
    Dim txtShellCommand As String

    If Me.Dirty Then
        RunCommand acCmdSaveRecord
    End If
    ' delete temporary table
    DoCmd.DeleteObject acTable, "tbltemp_cert"
    ' build sql string
    strSQL = "SELECT qryjobs.postal, qryjobs.payload, qryjobs.JobNumberFull, qryjobs.job_said, qryjobs.job_entrydate, qryjobs.job_number, qryjobs.job_description, qryjobs.job_required_by, qryjobs.job_client_ordernumber, "
    strSQL = strSQL & "qryjobs.job_complete_date, qryjobs.job_completed, qryjobs.cert_owner, qryjobs.cert_address, qryjobs.cert_vehicleyear, qryjobs.cert_vehiclemake, qryjobs.cert_vehiclemodel, qryjobs.cert_chassis, "
    strSQL = strSQL & "qryjobs.cert_vin, qryjobs.cert_rego, qryjobs.cert_axles, qryjobs.cert_application, qryjobs.cert_hubo, qryjobs.cert_huboserial, qryjobs.cert_readingdate, qryjobs.cert_hubo_expiry_km, "
    strSQL = strSQL & "qryjobs.cert_fleetnumber, qryjobs.cert_tare, qryjobs.cert_GVM, qryjobs.cert_GCM, qryjobs.cert_period, qryjobs.cert_expires, qryjobs.cert_MTM_braked, qryjobs.cert_MTM_unbraked, "
    strSQL = strSQL & "qryjobs.cert_front_axlerating, qryjobs.cert_rear_axlerating, qryjobs.cert_axle_spacings, qryjobs.cert_VSR_class, qryjobs.company, qryjobs.addr1line1, qryjobs.addr1line2, qryjobs.addr1line3, "
    strSQL = strSQL & "qryjobs.addr1line4, qryjobs.addr1city, qryjobs.addr1state, qryjobs.addr1postcode, qryjobs.addr2line1, qryjobs.addr2line2, qryjobs.addr2line3, qryjobs.addr2line4, qryjobs.addr2city, qryjobs.addr2state, "
    strSQL = strSQL & "qryjobs.addr2postcode, qryjobs.phone1, qryjobs.phone2, qryjobs.fax, qryjobs.identifier, qryjobs.salutation, qryjobs.contactname, qryjobs.notes, qryjobs.company_type, qryjobs.job_type_desc, "
    strSQL = strSQL & "qryjobs.job_type_code, qryjobs.job_type_LTSA_appr_code, qryjobs.job_type_designcode, qryjobs.job_type_cert_text, qryjobs.job_cert_word_doc, qryjobs.job_type2_desc, qryjobs.job_type2_code, "
    strSQL = strSQL & "qryjobs.job_type2_title, qryjobs.VSR_class, qryjobs.VSR_class_description, qryjobs.axle_description, qryjobs.vehicle_make, qryjobs.application_description, qryjobs.expired_now, qryjobs.cert_vertical_rating, qryjobs.vert_rating, "
    strSQL = strSQL & "qryjobs.qrywelders_all.Name, qryjobs.qrywelders_all.Employer, qryjobs.qrywelders_all.[4711No], qryjobs.qrywelders_all.Positions, qryjobs.qrywelders_all.Expires "
    strSQL = strSQL & "INTO tbltemp_cert FROM qryjobs WHERE [qryjobs.job_said] =" & Me!job_said & ";"

    ' write current record info to temp table
    DoCmd.RunSQL strSQL
    ' open & display selected word document according to job type
    ' the Shell function runs an executable program and returns a
    ' Variant (Double) representing the program's task ID if successful,
    ' otherwise it returns zero.
    txtWordPath = "C:\Program Files\Microsoft Office\root\Office16\Winword.exe"
    txtDocPath = Me![job_cert_word_doc]
    txtShellCommand = Chr(34) & txtWordPath & Chr(34) & " " & Chr(34) & txtDocPath & Chr(34)
    Debug.Print "shellcommand: " & txtShellCommand
    RetVal = Shell(txtShellCommand, 1)

Exit_btnPrintCert_Click:
    Exit Sub

Err_btnPrintCert_Click:
    MsgBox Err.Description
    Resume Exit_btnPrintCert_Click

End Sub

0 个答案:

没有答案