First, brackets are not required either in the Access user interface or through ADO. Just omit them in all environments and the problem should go away. (If this is an Access QBE property that adds parentheses, then consider another tool or instruction for creating SQL code!)
Secondly, even with the help of brackets, I cannot reproduce the error using your SQL code, for example.
Sub gjskdjs() On Error Resume Next Kill Environ$("temp") & "\DropMe.mdb" On Error GoTo 0 Dim cat Set cat = CreateObject("ADOX.Catalog") With cat .Create _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & _ Environ$("temp") & "\DropMe.mdb" With .ActiveConnection Dim Sql As String Sql = _ "CREATE TABLE tmp_binning" & vbCr & "(" & vbCr & " bn_faibash VARCHAR(255)," & _ " " & vbCr & " key2 VARCHAR(255)" & vbCr & ");" .Execute Sql Sql = _ "INSERT INTO tmp_binning (bn_faibash, key2)" & _ " VALUES ('002', '0210043-HOU-STOR');" .Execute Sql Sql = _ "INSERT INTO tmp_binning (bn_faibash, key2)" & _ " VALUES ('001', '0210043-HOU-STOR');" .Execute Sql Sql = _ "SELECT [tmp_binning].bn_faibash " & vbCr & " FROM" & _ " [tmp_binning] " & vbCr & " WHERE key2 = '0210043-HOU-STOR'" & _ " " & vbCr & " ORDER " & vbCr & " BY [tmp_binning].bn_faibash;" Dim rs Set rs = .Execute(Sql) MsgBox rs.GetString End With Set .ActiveConnection = Nothing End With End Sub
Consider placing your schema as an SQL DDL with sample data.
source share