Function booklvwRec(str As String)
Dim rs As New ADODB.Recordset
catlvw.ListItems.Clear
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
rs.MoveNext
End With
Wend
End Function

Recommended Answers

All 2 Replies

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 - http://www.connectionstrings.com

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.
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.