AccessToSQL



Option Explicit
Private Sub cmdConnect_Click()
Dim objConnection As Object
Dim objContents As Object
Dim strSQL As String
'Create the ADO connection. This is the handiest way to

'connect to a database in my uneducated opinion, so if you

'disagree, write your own code. ;-)

Set objConnection = CreateObject("ADODB.Connection")
'Next, open the connection to the database.

objConnection.Open "Driver={SQL Server};Server=Server;Database=Database;uid=sa;pwd=;"
'Now, for this next part to make sense, you'll need at least

'a little experience writing SQL queries. This is the simplest.

strSQL = "SELECT * FROM Table"
Set objContents = objConnection.execute(strSQL)
varResult = objContents(0)
varResult = objContents("<FIELD NAME>")
While objContents.BOF = False And objContents.EOF = False
varResult = objContents("<FIELD NAME>")
ListBox1.AddItem varResult
objContents.MoveNext ' This moves on To the next ROW
Wend
End Sub


(accesstosql.html)- by Paolo Puglisi - Modifica del 25/3/2019