Problems creating Workbook Connection programatically

  • Thread starter Thread starter MB34
  • Start date Start date
M

MB34

Why do I get a "Runtime error 5. Invalid procedure call or argument" error
with the code below?
We're trying to create our connections programatically.
This is called in the Workbook_Open event.


Sub CreateNewConnection()
Dim objConn As WorkbookConnection
Dim connstr As String
Dim cmdText As String

connstr = "ODBC;DRIVER={Advantage StreamlineSQL
ODBC};DataDirectory=C:\GC\JOSH;SERVER=OurDBServer; _

CharSet=ANSI;DefaultType=Advantage;Rows=False;AdvantageLocking=ON;Locking=Record; _

MemoBlockSize=64;MaxTableCloseCache=5;ServerTypes=6;TrimTrailingSpaces=False"
cmdText = "userglobals"


Set objConn = ThisWorkbook.Connections.Add( _
Name:="MyConnection", _
Description:="Description", _
ConnectionString:=connstr, _
CommandText:=cmdText, _
lCmdType:=xlCmdTable)

objConn.Refresh
End Sub
 
Back
Top