firoz.raj -3 Posting Pro in Training

can anybody tell me why i am getting error object variable or with
block variable not set .here is the code what i have written.
any help would be greately appreciated.

Public Sub Addtolistview()
'Dim success As Boolean
DataPath = GetSetting(Application.Name, "BasicSetup", "Database", "")
'StrQuotationStartID = GetSetting(Application.Name, "BasicSetup", "QuotationStartID", "1")
If DataPath = "" Then
   frmBasicSettings.Show (vbModal)
End If

Set con = New ADODB.Connection
Call OpenConnection(con)
'Set con = New ADODB.Connection
'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
[B]rs.CursorType = adOpenDynamic[/B]
rs.LockType = adLockOptimistic

strSql = "Select"
strSql = strSql & "[sup_name],[fax_no],[contact_person],[contact_no],[Office_address] from [Suppliers]"

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.
With ListView1
   .ColumnHeaders.Clear
'   Set colx = .ColumnHeaders.Add(, , ("Supplier No"), colWidth)
    Set colx = .ColumnHeaders.Add(, , ("Supplier Name"), ListView1.Width / 5)
    Set colx = .ColumnHeaders.Add(, , ("Fax No"), ListView1.Width / 5)
    Set colx = .ColumnHeaders.Add(, , ("Contact Person"), ListView1.Width / 5)
    Set colx = .ColumnHeaders.Add(, , ("Contact_no"), ListView1.Width / 5)
    Set colx = .ColumnHeaders.Add(, , ("Office_address"), ListView1.Width / 5)
End With
'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
        Wend
    End If
End With
Set rs = Nothing
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.