尝试将占位符值添加到Access VBA中的组合框

问题描述:

我有一个由查询填充的表单中的组合框。我想要做的是添加一个"选择名称";将持有者值作为组合框中显示的初始项目。我可以得到"选择姓名"作为默认值,但组合框的实际文本部分中不会弹出任何内容。我还尝试过将组合框的Text属性设置为"选择名称"的juts。但我遇到了这个运行时错误:

I have a combobox in a form that is populated by a Query.  What I would like to do is add a "Select Name" Place holder value as the initial item seen in the combobox.  I can get "Select Name" as the Default Value, but nothing will pop up in the actual text portion of the combobox.  I have also tried juts setting the Text property of the combobox to "Select Name" but I run into this runtime error:

"您无法为控件引用属性或方法除非控件具有焦点。"

"You can't reference a property or method for a control unless the control has the focus."

有什么想法吗?

您好

如果您的查询是静态的,即VBA未更改,我有一个解决方法。创建一个包含一条记录的表([Select Name]),在查询设计的SQL模式下为该表和您的currrent查询创建一个Union查询。使用此新联合查询作为组合框的数据。您的联合查询可能如下所示,其中table1是新表,Query15是您现有的查询

I have a workaround if your query is static, i.e. not changed by your VBA. Create a Table with one record ([Select Name]), in SQL mode in query design create a Union query for this table and your currrent query. Use this new union query as the data for your combobox. Your union query might look something like below, where table1 is the new table and Query15 is your existing query

TABLE [table1] UNION ALL SELECT * FROM Query15;

TABLE [table1] UNION ALL  SELECT * FROM Query15;

问候

ADG