建立一个窗体,其中有5个控件:
1.部门列表框list0;2.姓名列表框list1;
3.姓名文本框text1;4.电话文本框text2;5.住址文本框text3;
代码如下:
Private Sub Form_Load()
'窗体加载事件
Me.List0.RowSource = "select distinct 部门 from 部门"
Me.List1.RowSource = "select distinct 姓名 from 部门 where 部门='" & Me.List0.Value & "'"
End Sub
Private Sub List0_AfterUpdate()
'部门列表框单击事件
Me.List1.RowSource = "select distinct 姓名 from 部门 where 部门='" & Me.List0.Value & "'"
End Sub
Private Sub List1_AfterUpdate()
'姓名列表框单击事件
Me.RecordSource = "select * from 基本信息 where 姓名='" & Me.List1.Value & "'"
Me.Text1.ControlSource = "姓名"
Me.Text2.ControlSource = "电话"
Me.Text3.ControlSource = "住址"
End Sub
祝你成功!