1,216
社区成员
发帖
与我相关
我的任务
分享
Private Sub Workbook_Open()
Call sub_InitCombo
End Sub
Private Sub sub_InitCombo()
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strQ As String
con.CursorLocation = adUseClient
con.Open "Provider=MSDASQL.1;Driver={Microsoft ODBC for oracle};Server=my_db;UID=my_user;Pwd=my_password;"
strQ = "select my_filed from my_table"
rs.Open strQ, con, adOpenStatic, adLockOptimistic
If rs.RecordCount > 0 Then
With Sheet1.ComboBox1
.AddItem rs.Fields(0)
rs.MoveNext
End With
End If
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
End Sub