Me!cmbPrinter.RowSourceType = "Value List"
增加这一句,可以通过
Private Sub Form_Open(Cancel As Integer)
' 包含默认打印机索引的变量。
Dim strDefaultPrinter As String
' 包含打印机对象的变量。
Dim prt As Printer
' 在 AllReports 集合中遍历时
' 包含报表对象的变量。
Dim accObj As AccessObject
' 填写打印机列表。
' 确保 RowSource 为空。
Me!cmbPrinter.RowSource = ""
Me!lbxSelectReport.RowSource = ""
' 遍历计算机上已安装的打印机,并将它们添加到组合框中。 Me!cmbPrinter.RowSourceType = "Value List"
For Each prt In Application.Printers
' 使用新的 AddItem 方法将打印机名称添加到组合框中。
Me!cmbPrinter.AddItem prt.DeviceName
Next
' 记忆默认打印机。
strDefaultPrinter = Application.Printer.DeviceName
' 将组合框设置为默认打印机。
Me!cmbPrinter = strDefaultPrinter
Me!cmbPaperSize = 1
' 填写报表列表。
For Each accObj In CurrentProject.AllReports
Me!lbxSelectReport.AddItem accObj.Name
Next
' 将列表框设置为第一个报表。
Me!lbxSelectReport.SetFocus
Me!lbxSelectReport.ListIndex = 0
End Sub