I am 'playing' and learning with SQL and am creating a simple client interface in EXCEL / VBA with the following:-'Public sSQL As String'Public rs As ADODB.Recordset'Public cn As ADODB.Connection'Public cmdObj As ADODB.Command'Public My_SQL_db As String'Public My_SQL_Table As String'Public My_SQL_field As String My_cn = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Initial catalog = zzzzz ; Data Source = ACER-X1301\SQLEXPRESS" My_cn = Replace(My_cn, "zzzzz", My_SQL_db) If cn.State = adStateOpen Then cn.Close End If cn.Open My_cn Set rs = New ADODB.Recordset rs.CursorLocation = adUseClient t1 = sSQL ' rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText If rs.EOF Then
when I run the code I get an error at the above (EOF) '3704 Operation is not allowed when the object is closed'The t1= sSQL just enables t1 to be displayed in a the locals window