如何将Combobox设置为默认显示其第一个值。 [英] How to set the Combobox to showup its first value by default.

查看:1773
本文介绍了如何将Combobox设置为默认显示其第一个值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

这个论坛对像我这样的Access初学者非常有用。我相信我的问题只能在这个论坛上解决。

我有两个表(tblCustomers和tblOrders)和一个表格(frmOrders)用于数据输入,tblCustomers有以下字段:

CoID(自动编号)

客户ID(文字,PK)

CustomerFullName(文字)


tblOrders具有以下内容字段:

OrderID(自动编号,PK)

CustomerID(来自tblCustomers.CustomerID的查找文本)

产品(文字)

数量(文本)

价格(货币)


我将frmOrders设置为一个组合框,其中RowSource = SELECT [tblCustomers]。[CustomerID ] FROM tblCustomers WHERE tblCustomers.CoID = Forms!frmOrders!OrderID;

和[frmOders]的AfterUpdate事件![OrderID]设置为


私有子订单ID_AfterUpdate()

CustomerID.SetFocus

Me.CustomerID.Selected(0)= True

End Sub


intesion是保持Combobox的第一个值显示而不手动选择它。但是它保持其价值等待选择。

我在哪里做错了?

请帮忙!

Hi all!
This forum has been very usefully for the Access Beginners like me. I believe my problem can only be solved in this forum.
I have two tables (tblCustomers and tblOrders)and one form (frmOrders)for data entry, tblCustomers has the following fields:
CoID (Autonumber)
CustomerID (Text,PK)
CustomerFullName(Text)

The tblOrders has the following fields:
OrderID (Autonumber, PK)
CustomerID (Lookup Text from tblCustomers.CustomerID)
Product (Text)
Quantity (Text)
Price (Currency)

I set a frmOrders to be a combobox of which RowSource=SELECT [tblCustomers].[CustomerID] FROM tblCustomers WHERE tblCustomers.CoID=Forms!frmOrders!OrderID;
and the AfterUpdate event of [frmOders]![OrderID] set to

Private Sub OrderID_AfterUpdate()
CustomerID.SetFocus
Me.CustomerID.Selected(0) = True
End Sub

The intesion is to keep the first value of Combobox to showup without manually select it. But instead it keep its value waiting for selection.
Where did I do wrong on this?
Please help!

推荐答案

问题是组合框没有选定属性,只有列表框。在名为CustomerID的组合框中选择第一个项目:
The problem is that Combo Boxes do not have a Selected Property, only List Boxes. To Select the 1st Item in a Combo Box named CustomerID:
展开 | 选择 | Wrap | 行号


感谢您的回复。


我按照你的建议放置了代码,但它给出了错误。如果您调试并关闭打开的VBA,则字段将按预期更新。如何删除此错误。

让我附上示例数据库以获得更多说明!





Thanks for your imediate response.

I have placed the code as you suggested but it gives errors. If you debug and close the opened VBA the field is updated as expected. How to remove this error.
Let me attach the sample db for more clarifications!
附加文件
Combodb.zip (71.0 KB,476 views)
Attached Files
Combodb.zip (71.0 KB, 476 views)


抱歉,未使用Access 2007。
Sorry, not using Access 2007.


这篇关于如何将Combobox设置为默认显示其第一个值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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