View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
mike mike is offline
external usenet poster
 
Posts: 2
Default object is closed

hi
i wrote a macro to connect to a database using ADO
to retrieve some records

Private Sub Display()
Dim sql As String
Dim con As ADODB.Connection
Dim rs1 As ADODB.recordset

sql = "select * from table"
MsgBox sql

Set con = New ADODB.Connection
Set rs1 = New ADODB.recordset
con.Open "DSN=" & DSN & ";Database=" & DB & ";UID=" _
& User & ";PWD=" & Password
rs1.Open sql, con

If Not rs1.EOF Then <<---debugger points here..
MsgBox "Yes"
Else
MsgBox "No"
End If
rs1.Close
con.Close
End Sub

Whenever i run this, i would get error "Operation is not allowed when
the object is closed." and the debugger will point to the statement "If
Not rs1.EOF Then...". I tried using "Do Until rs1.EOF" but the error is
the same..
Can anyone advise me on what is wrong..thanks very much