从第一个表值Access中设置表单的组合框默认值

时间:2013-11-08 10:27:54

标签: ms-access combobox default-value

我查看有关此主题的信息,但没有任何影响。

我有一个名为TbKlient的Access'表,其中包含列ID(主键,自动编号)和名称(公司名称)和带有组合框cbName的Form FormTT1。我的目标很简单,但我无法做到这一点。所以我想,当我打开这个表单时,自动填充cbName组合框的默认值和第一行TbKlient的Name列。

欣赏所有的消化。谢谢!

1 个答案:

答案 0 :(得分:1)

尝试分配onOpen事件表格FromVT1

Private Sub Form_Open(Cancel As Integer)
dim rst as recordset

set rst=currentdb().openrecordset("SELECT [Name] FROM [TbKlient] ORDER BY [ID]") ' author, please check if you really want record with the lowest ID that is called by you "first record"

if not rst.eof then

    Me.cbName.DefaultValue = rst![Name] 

end if 

rst.close
set rst=nothing

end sub