While Not rs.EOF
Combo1.SelectItem.Add rs.Fields("字段名")
rs.MoveNext
Wend
Public Sub ShowSheetComboBox(ByRef List1 As ComboBox)If TableArray = "" Then
getTableArrayrem {这是函数}
Else
getTableArray rem {这是函数}
End If
List1.Clear
Dim TblArray As Variant
TblArray = Split(TableArray, ",")
For Each Item In TblArray
List1.AddItem Item
Next
End Sub
{下面括弧内的你要修改}
Public Sub getTableArray()
'd2
DoEvents
Dim cn As adodb.Connection
Set cn = New adodb.Connection
With cn
.ConnectionString = {sConnectionString}
.Open
End With
Dim rs As adodb.Recordset
Set rs = cn.Execute("Select {Colname} from { tablename} ")
TableArray = ""
Do
If Not rs.EOF Then
If TableArray = "" Then
TableArray = TableArray &rs(0).Value
Else
TableArray = TableArray &"," &rs(0).Value
End If
End If
rs.MoveNext
Loop While Not rs.EOF
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)