2、如果引用ACCESS做为单元格中数据有效性的下拉选框或控件的下拉选框如何做呀?(详见附件)
Private Sub UserForm_Initialize()
Dim RS1 As Recordset
Dim DB1 As Database
On Error GoTo 1000
Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "学生档案.MDB")
Set RS1 = DB1.OpenRecordset(Name:="档案", Type:=dbOpenDynaset)
RS1.MoveLast
RS1.MoveFirst
For I = 1 To RS1.RecordCount
ComboBox1.AddItem RS1.Fields("姓名")
RS1.MoveNext
Next I
DB1.Close
Exit Sub
1000:
DB1.Close
End Sub
利用1楼的例子,在UserForm2上用以下代码取得数据库中”籍贯“字段的所有数据,如果取得数据库中”籍贯“字段的唯一值代码如何写?
Private Sub UserForm_Initialize()
Dim RS1 As Recordset
Dim DB1 As Database
On Error GoTo 1000
ComboBox3.AddItem "男"
ComboBox3.AddItem "女"
Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "学生档案.MDB")
Set RS1 = DB1.OpenRecordset(Name:="档案", Type:=dbOpenDynaset)
RS1.MoveLast
RS1.MoveFirst
For I = 1 To RS1.RecordCount
ComboBox2.AddItem RS1.Fields("籍贯")
RS1.MoveNext
Next I
DB1.Close
Exit Sub
1000:
DB1.Close
End Sub
[此贴子已经被作者于2005-5-18 17:03:27编辑过] |