firoz.raj -3 Posting Pro in Training

Can anybody tell me .why i am getting error object variable not set.
Kindly help me.any help would be Greatly appreciated.here is the
code what i have written.

Public Sub Addtolistview()
Dim con As adodb.Connection, rs As adodb.Recordset
Set con = New adodb.Connection
Call OpenConnection(con)
If Not OpenConnection(con) Then
   MsgBox ("cannot open connection")
   Set con = Nothing
End If
'con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
'Call OpenConnection(con)
Set rs = New adodb.Recordset
rs.CursorLocation = adUseClient
'strSql = "Select"
'strSql = strSql & "[sup_name],[fax_no],[contact_person],[contact_no],[Office_address] from [Suppliers]"
strSql = "SELECT Suppliers.sup_id, Suppliers.sup_name, ItemTypes.item_Type, Suppliers.Fax_No, Suppliers.Contact_Person, Suppliers.Contact_No, Suppliers.Office_Address, Suppliers.Email, Suppliers.Website FROM ItemTypes INNER JOIN Suppliers ON ItemTypes.Type_ID = Suppliers.Type_ID;"
rs.Open strSql, con, adOpenDynamic, adLockOptimistic
ListView1.View = lvwReport
'ListView1.BorderStyle = ccFixedSingle
ListView1.FullRowSelect = True
ListView1.BorderStyle = ccNone
'checking the width of listview control and divided by 5...so that all columns become of same width...here we used 5 because the control will have 5 columns
colWidth = ListView1.Width / 5
ListView1.ListItems.Clear

'here we are adding the columns
'you need similar no. of columns as much no. of listitems you want to add to the listview. now if you want to hide any column from displaying, just set its width to 0.

'adding rows to listview
 With ListView1
'   .ListItems.Clear
    If rs.RecordCount > 0 Then
        rs.MoveFirst
        While Not rs.EOF()
            Dim faxno, contactNo, officeAddress As String
            faxno = IIf(IsNull(rs!fax_no), "", rs!fax_no)
            contact = IIf(IsNull(rs!contact_person), "", rs!contact_person)
            suppliername = IIf(IsNull(rs!sup_name), "", rs!sup_name)
            contactNo = IIf(IsNull(rs!Contact_no), "", rs!Contact_no)
            officeAddress = IIf(IsNull(rs!office_address), "", rs!office_address)
            Set listitem = ListView1.ListItems.Add(, , supplier_name)
            listitem.Text = IIf(IsNull(rs!sup_name), "", rs!sup_name)
            listitem.SubItems(1) = rs.Fields("fax_no").Value & vbNullString
            listitem.SubItems(2) = rs.Fields("contact_person").Value & vbNullString
            listitem.SubItems(3) = rs.Fields("contact_no").Value & vbNullString
            listitem.SubItems(4) = rs.Fields("Office_address").Value & vbNullString
            rs.MoveNext
           Call CloseRecordset(rs)
        Wend
    End If
End With
Call CloseConnection(con)
End Sub
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.