Getting Supplier detail using listview

Reply

Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Getting Supplier detail using listview

 
0
  #1
Feb 10th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Getting Supplier detail using listview

 
0
  #2
Feb 10th, 2009
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
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Re: Getting Supplier detail using listview

 
0
  #3
Feb 10th, 2009
sir i am getting runtime error 91.kindly find the attachmlistview.docent.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Getting Supplier detail using listview

 
0
  #4
Feb 10th, 2009
Well it's very clear as the sunshine. You have just used the "rs" but not declaring/setting it.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Re: Getting Supplier detail using listview

 
0
  #5
Feb 11th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Getting Supplier detail using listview

 
0
  #6
Feb 11th, 2009
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.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Getting Supplier detail using listview

 
0
  #7
Feb 11th, 2009
Originally Posted by jireh View Post
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.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Re: Getting Supplier detail using listview

 
0
  #8
Feb 11th, 2009
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
Last edited by firoz.raj; Feb 11th, 2009 at 7:12 am.
Attached Files
File Type: doc error.doc (68.5 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Getting Supplier detail using listview

 
0
  #9
Feb 11th, 2009
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.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 292
Reputation: firoz.raj is an unknown quantity at this point 
Solved Threads: 1
firoz.raj firoz.raj is offline Offline
Posting Whiz in Training

Re: Getting Supplier detail using listview

 
0
  #10
Feb 11th, 2009
Supplier.zip
kindly find the attachment.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC