如何传递给combobox的引用? [英] How to pass reference to combobox?

查看:244
本文介绍了如何传递给combobox的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我前一篇文章的延续:如何为整个工作选择打印机?,其中我基本上要打印一系列来自Access数据库表单的报告。

This is a continuation from a previous post of mine: How to select a printer for entire job?, where I basically want to print a series of reports from a form in my Access database.

这是指帮助doc: https://msdn.microsoft.com/ en-us / library / ee336132(v = office.12).aspx

我试图创建带有活动打印机的组合框以临时更改一系列文档的默认打印机。我如何实现这个?

I'm trying to create the combobox with active printers in it in order to temporarily change the default printer for a series of documents. I'm tripped up on where it says "pass a reference to a ComboBox control"... How does one implement this?

这里是我到目前为止的代码,其中 cboPrinterSelect 是组合框名称:

Here's the code I have so far, where cboPrinterSelect is the combobox name:

Private Sub cboPrinterSelect_Load(Cancel As Integer)
    Call GetPrinterList
    ' I'm not sure about this next part either'
    cboPrinterSelect.Value = GetPrinterList.value
End Sub

'***************************************************
Private Sub cboPrinterSelect_AfterUpdate(Cancel As Integer)
    Set Application.Printer = Application.Printers(cboPrinterSelect.ListIndex)
End Sub
'***************************************************

Private Sub GetPrinterList(ctl As Control)
    Dim prt As Printer
    For Each prt In Printers
        ctl.AddItem prt.DeviceName
    Next prt
    ctl = Application.Printer.DeviceName    
End Sub

任何帮助/建议都不胜感激。

Any help/advice would be appreciated.

EDIT:

这是我更新的代码,它仍然会引发错误评论):

Here is my updated code, which is still throwing an error (described in Andre's comments):

Private Sub Form_Load()
    Call GetPrinterList(Me.cboPrinterSelect)
End Sub

'*********************************************************

Private Sub cboPrinterSelect_AfterUpdate(Cancel As Integer)

Set Application.Printer = Application.Printers(cboPrinterSelect.ListIndex)

End Sub

'***************************************************************

Private Sub GetPrinterList(ctl As Control)

Dim prt As Printer
For Each prt In Printers
    ctl.AddItem prt.DeviceName
Next prt
ctl = Application.Printer.DeviceName

End Sub


推荐答案

GetPrinterList()的调用必须进入形式的 On Load 事件

The first part, the call of GetPrinterList(), must go into the On Load event of the form.

Private Sub Form_Load()
    Call GetPrinterList(Me.cboPrinterSelect)
End Sub

这应该是所有的缺失。

默认打印机由此行预先选择:

The default printer is pre-selected by this line:

ctl = Application.Printer.DeviceName

并确保cboPrinterSelect的RowSourceType为值列表

And make sure that cboPrinterSelect has a RowSourceType of Value List.

这篇关于如何传递给combobox的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆