Last active
May 25, 2018 15:59
-
-
Save skazuki0430/9a6a9f8376bac873dbaebd4d609e033b to your computer and use it in GitHub Desktop.
Execute Query from VBA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim cnn As New ADODB.Connection | |
Dim cmd As New ADODB.Command | |
Dim rs As New ADODB.Recordset | |
Public Function Connect(ServerName As String, DBName As String, UserId As String, Password As String) | |
Dim connectionString As String | |
connectionString = "Provider=SQLOLEDB;" & _ | |
"Data Source=" & ServerName & ";" & _ | |
"Initial Catalog=" & DBName | |
cnn.Open connectionString, userid, password | |
cmd.ActiveConnection = cnn | |
End Function | |
Public Function Disconnect() | |
cnn.Close | |
Set cmd = Nothing | |
Set cnn = Nothing | |
End Function | |
Public Function ExecuteQuery(Query As String) | |
cmd.CommandText = Query | |
cmd.Execute | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment