I have a function that is passed a SQL string, queries a SQL server, and return the results via a an array. This function works perfectly the first time, but I try to call it again it get:
Operation is not allowed when the object is closed
Oddly enough this error occures right after the Open statement. I've Googled about everything I can think of, with no good results.
Public Function SQL_Query(SQLCommand As String) As Variant Dim cn As New ADODB.Connection Dim SQLrs As New ADODB.Recordset cn.ConnectionString = "Provider=SQLNCLI11;Server=10.XXX.XXXX.XXX;DataBase=Database1;Trusted_Connection=yes;" cn.Open SQLrs.CursorLocation = adUseClient Call SQLrs.Open(SQLCommand, cn, adOpenStatic, adLockBatchOptimistic) SQLrs.MoveFirst SQL_Query = RecordSet2Array(SQLrs.GetRows) SQLrs.Close Set SQLrs = Nothing cn.Close Set cn = Nothing End Function