A1VBCode Forums

VBA alternation to VB.Net sql connection


http://www.a1vbcode.com/vbforums/Topic31904.aspx

By mehowski - 3/3/2013

As this is my first post on your forum I would like to say a warm Hello World! to everyone Smile

I have received a sample code to establish a connection to an external database. Unfortunately, this code is in VB.NET which does not really match my request. I think its possible to find an alternate code that will work with VBA, and that is why I am here seeking your help.

I will be very thankful for any advice.



Imports System.Data.SqlClient

Using Connection As New SqlConnection("Data Source={server}\{instance};Initial Catalog=master;User ID={Username};Password={Password}")

Connection.Open()

Dim ret As SqlCommand = Connection.CreateCommand

ret.CommandText = String.Format("use {0}; {1}", Environment, "[Your SQL here]")

End Using