Have Connection, but no values added in Drop Down (MSSQL Connectio

D

Dia Nagele

I have the connection to the database.
I have a drop down on the page.
I am not understanding the "fill" process.
Can someone help out??


Dim MyDB As ADODB.Connection, MyRS As ADODB.Recordset
Dim SQLStr As String
Set MyDB = New ADODB.Connection
MyDB.Open ("Provider=SQLOLEDB; Data Source=MyServer; Initial
Catalog=MyDb;Trusted_Connection=yes;")
Set MyRS = New ADODB.Recordset
With MyRS
.CursorLocation = adUseClient
' Modify the SQL String to retrieve the columns you want from your
Table
' * in SQL means all columns; use SELECT Name, Code, .... FROM MyTable
' if you need to specify the columns
SQLStr = "SELECT City FROM TaxRateInfo_tbl"
.Open SQLStr, MyDB, adOpenDynamic, adLockReadOnly
' The above performed the query and stored the result in MyRS
' MyRS.RecordCount gives the number of records returned
If .RecordCount = 0 Then
MsgBox "No records; abort processing"
Else
MsgBox "Yes! Eureka we have records!"
For i = 1 To RecordCount
ActiveSheet.ComboBox1.AddItem .Fields(0)
Next i
End If
..Close
End With
MyDB.Close
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top