|
此代码中 If Forms!流动关系选人窗体!lstPrint.Column(2) = "招聘" Then 句存在:事先在!lstPrint.列表框中任一记录点击一下,属“招聘”人员能打印出“毕业生介绍信”,否则识别不了,只能打印出“干部介绍信”。事先点击后一切正常。如何不用点击,让程序自动识别条件打印出相应的介绍信来?
Private Sub Command2_Click()
On Error GoTo catch
If MsgBox("确定已经选择介绍信编号?", vbYesNo, "系统提示") = vbYes Then
Dim temp As Integer, result As String
result = ""
If lstPrint.ListCount > 0 Then
For temp = 0 To (lstPrint.ListCount - 1)
result = result & " (员工流动.姓名 = '" & lstPrint.ItemData(temp) & "') OR"
Next temp
If Forms!流动关系选人窗体!lstPrint.Column(2) = "招聘" Then
DoCmd.OpenReport "毕业生介绍信", acViewPreview, , , , Left(result, Len(result) - 3)
MsgBox "打印介绍信"
If Forms!流动关系选人窗体!Text16 > 5 Then
DoCmd.OpenReport "毕业生介绍信附件", acViewPreview, , , , Left(result, Len(result) - 3)
End If
Else
DoCmd.OpenReport "调动介绍信", acViewPreview, , , , Left(result, Len(result) - 3)
MsgBox "打印介绍信"
If Forms!流动关系选人窗体!Text16 > 5 Then
DoCmd.OpenReport "调动介绍信附件", acViewPreview, , , , Left(result, Len(result) - 3)
End If
End If
DoCmd.PrintOut acPages, 1, 1, , 1 '从第1页到第1页,打印1份
Else
MsgBox "没有选择打印对象", vbExclamation, "提示"
Exit Sub
End If
finally:
Exit Sub
catch:
MsgBox err.Number & vbNewLine & err.Description
Resume finally
End If
End Sub |
|