客户字段和产品字段从窗体上传递到word客户字段及产品字段上的是绑定列的值(如1或2),这不是我需要的,我需要的是显示的值(如三通公司/AA沙发)。我不知道在代码中如何修改,请帮助!
Private Sub 打印_Click()
DoCmd.RunCommand acCmdSaveRecord '打印前先保存记录
Const maxRecordsInOnepage As Integer = 7 '发票最多可以打印的明细条数
Dim currentDetailsRecords As Integer
Dim totalPages As Integer
Dim I, N As Integer
'使用DAO操作打开明细记录集
Dim rstDetails As DAO.Recordset
Set rstDetails = CurrentDb.OpenRecordset("SELECT 货号, 产品ID, 单位, 数量, 单价, 金额 FROM 送货明细表1 WHERE 送货单号='" & Me.送货单号 & "'")
'如果没有记录 , 不执行下面程序
If rstDetails.EOF Then Exit Sub
'为了能得到记录总数量,DAO记录集要先把记录集位置移到最后,否则得不到RECORDCOUNT
rstDetails.MoveLast
rstDetails.MoveFirst
currentDetailsRecords = rstDetails.RecordCount
If currentDetailsRecords <= maxRecordsInOnepage Then '一页
totalPages = 1
Else
If currentDetailsRecords Mod maxRecordsInOnepage = 0 Then '除得尽,
totalPages = currentDetailsRecords / maxRecordsInOnepage
Else '除不尽
totalPages = Int(currentDetailsRecords / maxRecordsInOnepage) + 1
End If
End If
On Error Resume Next
Dim docApp As Object
Set docApp = GetObject(, "Word.Application") '得到当前的WORD程序对象,如果WORD已经运行
If Err Then '出错说明WORD没有运行
Err.Clear
Set docApp = CreateObject("Word.Application") '创建WORD对象
If Err Then
MsgBox "操作中没有装WORD程序!", vbQuestion, "发票套打程序"
Exit Sub
End If
End If
docApp.Visible = False '隐藏WORD程序,防止在执行程序时用户误操作
Dim doc As Object
Dim win As Object
For I = 1 To totalPages '多页的处理,使用循环
Set doc = docApp.Documents.Add(CurrentProject.Path & "\发票模板.doc") '使用定义好的模板创建新文件
Set win = doc.ActiveWindow