0% found this document useful (0 votes)
6 views1 page

Conn, Vbs

The document contains a VBA script that establishes a connection to a SQL Server database using ADODB. It executes a SQL query to select all records from the 'Customers' table and prints the 'CustomerName' field for each record. Finally, it closes the recordset and the database connection.

Uploaded by

fax6500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Conn, Vbs

The document contains a VBA script that establishes a connection to a SQL Server database using ADODB. It executes a SQL query to select all records from the 'Customers' table and prints the 'CustomerName' field for each record. Finally, it closes the recordset and the database connection.

Uploaded by

fax6500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Dim conn As Object

Set conn = CreateObject("ADODB.Connection")

conn.Open "Driver={SQL
Server};Server=MyServer;Database=MyDB;Trusted_Connection=Yes;"

Dim rs As Object
Set rs = conn.Execute("SELECT * FROM Customers")

' Loop through data


Do While Not rs.EOF
Debug.Print rs.Fields("CustomerName")
rs.MoveNext
Loop

rs.Close
conn.Close

You might also like