1.11M Members

Need a good Loop Statement

 
0
 

i have a listview in a form that contains a name like "Aileen-EB" , "FEMA-EB" , "CARMEN-EB7" , "TONETTE-A"
something like that

I need to get them and put it on a

Dim AccountName as String

I use if statement but i want my code to be like this

For AccountName 
Loop
Next

Something like that please help me guys
I attached a screenshot of my listview
i want the AM Field to input in the AccountName

Listview

Attachments
 
0
 

Please clarify what you want to do.

i want the AM Field to input in the AccountName

is unclear.

I need to get them and put it on a

Dim AccountName as String

You already have them. They are in the ListView.

 
0
 

yes it is in the listview i want each of the code name to go into the

   dim AccountName as string

so that each time i click the selected they will go to the AccountName
like this

AccountName = "ERVIE-A" & "GENNA-D" 'it will add if i click again

then if i click again it will add another
I want them to search all the data in the AccountName

"Select * from [Calls and Visits$] where AM like '" & AccountName & "%'", con

Sorry for the bad english and explanation..

 
0
 

So every time the user clicks on a line in the listview you want to append the value from the Code Name column to AccountName. The query

"Select * from [Calls and Visits$] where AM like '" & AccountName & "%'

will never match any records if AccountName contains more than one Code Name.

 
0
 

yes i know but how can i do that to append?

 
0
 

@Reverend Jim i want to revise something
I want all my listview in code name to store or append in a string
so that i can easily use this code

For AccountName = ???
    "Select * from [Calls and Visits$] where AM like '" & AccountName & "%'"
Loop until listview.eof?

something like that????

 
1
 

So in pseudo code

For Each "Code Name" in the listview
    get all calls and visits for that Code Name
Next

and in real code that is

Dim query As String

For Each item As ListViewItem In ListView1.Items
    query = "Select * from [Calls and Visits$] where AM like '" & item.SubItems(1).Text & "%'"
    'execute the query and do something with the results
Next
 
0
 

wow thank you so much @Reverend Jim for the codes
i will try this right now :)

 
0
 

Hi @reverend Jim

i have a question for this one

Dim query As String
For Each item As ListViewItem In ListView1.Items
query = "Select * from [Calls and Visits$] where AM like '" & item.SubItems(1).Text & "%'"
'execute the query and do something with the results
Next

so my code will going to be

        Dim con As New OleDbConnection
        Dim FilePath As String = FormConnection.TextPathCallsVisits.Text

        Dim dt As New DataTable
        Dim ds As New DataSet
        con.ConnectionString = ("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & FilePath & "';Extended Properties=Excel 8.0;")
        con.Open()
        ' this will find all the item in lvAccountManager
        For Each item As ListViewItem In lvAccountManager.Items
            Dim da As New OleDbDataAdapter("Select * from [Calls and Visits$] where AM like '" & item.SubItems(1).Text & "%'", con)

        ' this one will put all the AM that the systems find in the Listview
            da.Fill(dt)
            Dim dc As DataColumn
            For Each dc In ds.Tables(0).Columns
                Dim ch As New ColumnHeader
                ch.Text = dc.ColumnName
                ch.Width = 105
                Me.ListView1.Columns.Add(ch)
            Next
            ' Importing all data from Excel to Listview
            For Each myRow In dt.Rows
                Me.ListView1.Items.Add(myRow.Item(0))
                Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(1))
                Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(2))
                Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(3))
                Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(4))
            Next
            con.Close()

        Next
 
0
 

anyways i got it right :) thanks @reverend

        Dim con As New OleDbConnection
        Dim FilePath As String

        Dim dt As New DataTable
        Dim ds As New DataSet
        FilePath = FormConnection.TextPathCallsVisits.Text
        con.ConnectionString = ("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & FilePath & "';Extended Properties=Excel 8.0;")
        con.Open()
        dt.Clear()
        ds.Tables.Add(dt)
        For Each item As ListViewItem In lvAccountManager.Items
            Dim da As New OleDbDataAdapter("Select * from [Calls and Visits$] where AM like '" & item.SubItems(0).Text & "%'", con)
            da.Fill(dt)
        Next

        Dim dc As DataColumn
        For Each dc In ds.Tables(0).Columns
            Dim ch As New ColumnHeader
            ch.Text = dc.ColumnName
            ch.Width = 105
            Me.ListView1.Columns.Add(ch)
        Next

        For Each myRow In dt.Rows
            Me.ListView1.Items.Add(myRow.Item(0))
            Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(1))
            Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(2))
            Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(3))
            Me.ListView1.Items(Me.ListView1.Items.Count - 1).SubItems.Add(myRow.Item(4))
        Next
        con.Close()

I hope you can help me again :) THANK YOU SO MUCH

Question Answered as of 1 Year Ago by Reverend Jim
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: