Question : open Database connection on excel vba example

Hi,
I need help to guide me how could I open connection, recordset from excel vba
what I looking is ODBC connection with recordset and paste records on excel cells....
That's !
Thank you!

Answer : open Database connection on excel vba example

hi, try below code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset

cnn.Open "YourDSN", "YourUsername", "YourPassword"
rst.ActiveConnection = cnn
rst.CursorLocation = adUseServer

rst.Source = "SELECT * FROM TABLE WHERE FIELD='data'"
rst.Open
variable = rst.Fields("FIELD") ' Do whatever you need to the data
rst.Close

Set rst = Nothing
Set cnn = Nothing
Random Solutions  
 
programming4us programming4us