I'm trying to use the GO statement in a query passed to SQL Server 2017 from VBA code in MS Access 2019. The execution results in runtime error:
80040e14 "Incorrect syntax near GO".
Exactly the same query executed in SSMS works fine.
What am I doing wrong? It works if I remove the GO line.
In Access Module:
Public SQLDB As Object
Public ADOcom As Object
Public Const adCmdText as Long = 1
Sub CreateDB()
Dim sql As String, connectionstring As String
connectionstring = "Driver={SQL Server Native Client 11.0};" & _
"Server=MySQLServer;" & _
"Trusted_Connection=yes;" & _
"Provider=SQLNCLI11;" & _
"DataTypeCompatibility=80;" & _
"MARS Connection=True;"
Set SQLDB = CreateObject("ADODB.Connection")
Set ADOcom = CreateObject("ADODB.Command")
SQLDB.Open connectionstring
Set ADOcom.ActiveConnection = SQLDB
ADOcom.CommandType = adCmdText
sql = "USE Master;" & vbCrLf & _
"GO" & vbCrLf & _
"CREATE DATABASE MyTest"
ADOcom.CommandText = sql
ADOcom.Execute
End Sub