943,859 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Feb 10th, 2009
0

Getting Supplier detail using listview

Expand Post »
Can anybody tell me why these statement is not working ?. I want to see supplier detail using listview.here is the code what i have written.
Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
con.CursorLocation = adUseClient
   Dim listitem As listitem
   ListView1.View = lvwReport
   ListView1.ColumnHeaders.Add , , "Supplier No."
   ListView1.ColumnHeaders.Add , , "Supplier Name"
   ListView1.ColumnHeaders.Add , , "Contact Person"
StrSql = "Select"
StrSql = StrSql & "[supplier_name],[type],[fax_no],[contact_person]"
StrSql = StrSql & "From  [Supplier]"
rs.Open StrSql, con, adOpenDynamic, adLockOptimistic
While (Not (rs.EOF))
    Set listitem = ListView1.ListItems.Add(suppliername)
    listitem.SubItems(1) = IIf(IsNull(rs!supplier_name), "", rs!supplier_name)
    listitem.SubItems(2) = IIf(IsNull(rs!Type), "", rs!Type)
    listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no)
    listitem.SubItems(4) = IIf(IsNull(rs!contact_person), "", rs!contact_person)
Wend
End Sub
Last edited by firoz.raj; Feb 10th, 2009 at 2:37 am.
Reputation Points: 7
Solved Threads: 1
Posting Pro in Training
firoz.raj is offline Offline
415 posts
since Dec 2008
Feb 10th, 2009
0

Re: Getting Supplier detail using listview

your code has some problems that I noticed....anyways this code can be improved...but could you explain what is happening actually when you running this?

what's d error msg you are getting....what's the output coming?

regards
Shouvik
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Feb 10th, 2009
0

Re: Getting Supplier detail using listview

sir i am getting runtime error 91.kindly find the attachmlistview.docent.
Reputation Points: 7
Solved Threads: 1
Posting Pro in Training
firoz.raj is offline Offline
415 posts
since Dec 2008
Feb 10th, 2009
0

Re: Getting Supplier detail using listview

Well it's very clear as the sunshine. You have just used the "rs" but not declaring/setting it.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Feb 11th, 2009
0

Re: Getting Supplier detail using listview

Now i got invalid use of null value.when i uncomment the follwing
line get invalid property value.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no)
here is the code :
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim listitem As listitem
Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")
con.CursorLocation = adUseClient
   ListView1.View = lvwReport
   ListView1.ColumnHeaders.Add , , "Supplier No."
   ListView1.ColumnHeaders.Add , , "Supplier Name"
   ListView1.ColumnHeaders.Add , , "Contact Person"
StrSql = "Select"
StrSql = StrSql & "[supplier_name],[type],[fax_no],[contact_person] from [Supplier]"
Set rs = New ADODB.Recordset
rs.Open StrSql, con, adOpenDynamic, adLockOptimistic
   While (Not rs.EOF)
        Set listitem = ListView1.ListItems.Add(, , , supplier_name)
        listitem.SubItems(1) = rs!supplier_name
        listitem.SubItems(2) = rs!Type
'       listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no)
        listitem.SubItems(3) = rs!fax_no
        listitem.SubItems(4) = rs!contact_person
        Wend
        End Sub
Last edited by firoz.raj; Feb 11th, 2009 at 2:03 am.
Reputation Points: 7
Solved Threads: 1
Posting Pro in Training
firoz.raj is offline Offline
415 posts
since Dec 2008
Feb 11th, 2009
0

Re: Getting Supplier detail using listview

hi....here is the modified code...just check this out....look for the BOLDED lines....these are where i made some changes....watch GREEN lines for comments....

the problem is within your listview manipulation code.....means when you are adding listitems.....you have mismatched total no. of columns and listitems.....total no. of columns in the listview should match with total no. of listitems you want to add....the problem is you adding 5 listitems to the control where you are having only 3 columns....so that's why the error is coming....

just follow this code and hope you will solve ur problem...

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim listitem As listitem

this is for adding the columns to the lv control
Dim colx As Columnheader
this is for measuring column widths
Dim colWidth As Double

Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\asfserver\itp$\Product_tabletest.mdb")

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic

StrSql = "Select"
StrSql = StrSql & "[supplier_name],[type],[fax_no],[contact_person] from [Supplier]"

rs.Open StrSql, con
   
ListView1.View = lvwReport

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

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"), colWidth)
    Set colx = .ColumnHeaders.ADD(, , ("Type"), colWidth)
    Set colx = .ColumnHeaders.ADD(, , ("Fax No"), colWidth)
    Set colx = .ColumnHeaders.ADD(, , ("Contact Person"), colWidth)
End With
   
adding rows to listview
With ListView1
    .ListItems.Clear
    If rs.RecordCount > 0 Then
        rs.MoveFirst
        While Not rs.EOF()
            Set listitem = .ListItems.ADD(, , (supplier_no))
            listitem.SubItems(1) = rs!supplier_name
            listitem.SubItems(2) = rs!Type
            listitem.SubItems(3) = IIf(IsNull(rs!fax_no), "", rs!fax_no)
            listitem.SubItems(4) = rs!contact_person
            
            rs.MoveNext
        Wend
    End If
End With

closing the recordset so the memory can be utilized again and also releasing its current instance from the memory
If rs.state = adStateOpen Then rs.Close
Set rs = Nothing
End Sub

Hope this helps.....please make a feedback here...

regards
Shouvik
Last edited by choudhuryshouvi; Feb 11th, 2009 at 4:25 am.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Feb 11th, 2009
0

Re: Getting Supplier detail using listview

Click to Expand / Collapse  Quote originally posted by jireh ...
Well it's very clear as the sunshine. You have just used the "rs" but not declaring/setting it.

that's true....he forgot to create an instance....but already fixed that...
he..he.
Last edited by choudhuryshouvi; Feb 11th, 2009 at 4:32 am.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Feb 11th, 2009
0

Re: Getting Supplier detail using listview

Now i got item cannot be found in the collection corresponding to the requested name or ordinal.kindly help me anybody.
With ListView1
    .ListItems.Clear
    If rs.RecordCount > 0 Then
        rs.MoveFirst
        While Not rs.EOF()
            Set listitem = .ListItems.Add(, , (supplier_no))
'           listitem.SubItems(1) = rs!supplier_name
            listitem.SubItems(1) = IIf(IsNull(rs!supplier_name), "", rs!supplier!Name)
            listitem.SubItems(3) = IIf(IsNull(rs_Type), "", rs!Type)
            listitem.SubItems(3) = IIf(IsNull(rs_fax_no), "", rs!fax_no)
            listitem.SubItems(4) = IIf(IsNull(rs!contact_person), "", rs!contact_person)
'           listitem.SubItems(4) = rs!contact_person
            
            rs.MoveNext
        Wend
    End If
End With
Attached Files
File Type: doc error.doc (68.5 KB, 18 views)
Last edited by firoz.raj; Feb 11th, 2009 at 7:12 am.
Reputation Points: 7
Solved Threads: 1
Posting Pro in Training
firoz.raj is offline Offline
415 posts
since Dec 2008
Feb 11th, 2009
0

Re: Getting Supplier detail using listview

item cannot be found in the collection corresponding to the requested name or ordinal --> this means you donot have a column with name "supplier_name" in the table...

check the sql statement...whether you are opening the correct table or not...
the table must have the column "supplier_name" in it....

for better observation please upload your full code here....

regards
Shouvik
Last edited by choudhuryshouvi; Feb 11th, 2009 at 7:24 am.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Feb 11th, 2009
0

Re: Getting Supplier detail using listview

Supplier.zip
kindly find the attachment.
Reputation Points: 7
Solved Threads: 1
Posting Pro in Training
firoz.raj is offline Offline
415 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: vb 6-ocacle on linux connectivity
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: timer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC