Function booklvwRec(str As String)
Dim rs As New ADODB.Recordset
rs.Open str, connect, 2, 3 (this section has an error, what is the error in this section) and the error state that: "the connection cannot be used to perform this operation. it is either closed or invalid in this connection"
While Not rs.EOF
With catlvw.ListItems.Add(, , rs!book)
With .ListSubItems
.Add , , rs!author
.Add , , rs!acc
.Add , , rs!Call
.Add , , rs!tbltransactions
End With
End With
End Function

rs.Open str, connect, 2, 3

Connect seems to be your problem. Firstly, is your function private or public?

You have the rs.Open part correct but no reference to "str", which will be the sql string. This should be something like

Dim str as String
str = "SELECT * FROM MyTable"

The connect part should be -

Dim Connect As ADODB.Connection
Set connect = New ADODB.Connection
connect.Open .....

The connect open part will depend on what database you are using, Access, Sql, MySql etc. You can get the correct connection string for your database at -

Yes andreret has your answer and let me remind you "Please don't color your fonts by yourself. When you paste code use (CODE) button.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.