In a list box some email
now I will that the corresponding name to
the email

     rs.MoveLast
     rs.MoveFirst
     max = rs.RecordCount
     rs.MoveFirst
     LstData3.Clear
     List1e.Clear
    For i = 1 To max


     If Not Len(Trim(rs("Email"))) = 0 Then LstData3.AddItem rs("email") & "          " & rs("eftn") & "     " & rs("namn")


    If Not Len(Trim(rs("Email1"))) = 0 Then LstData3.AddItem rs("Email1") & "          " & rs("eftn") & "     " & rs("namn")
    rs.MoveNext

it working fine but the rs("eftn") and rs("namn")
is coming just after the email
now my question is how to count the email letters
so I can get space between the email and the EFTN and NAMN

sorry the LIST1E should not be there

You are already using the Len() method. So you need to dim an integer like dim intLen and than assign it the Len of your email
like: intLen= Len(Trim(rs("Email1"))). Alternatively you can count the characters in a string.

I will test it
Thank's

it looks like this now and it's not nice

where you are printing the result ? on form ? or other place holder ?

i am not printing it out at all, just to show how it looks in then listbox

sorry for my internet is bad, how can I get the names in the same listbox to
be at the longest email's end with a space(10) spaces

seems contraversy between the picture you added here and your last reply ?
you wanna show email in listbox , thats ok. i got it but what about spaces , what you want to say about spaces ?

email in listbox is Ok
but I will have the corresponding names
in a listbox2 that is connected with the email

The trick now is to keep your listboxes synchronised via the index properties of the listboxes. Clear the listboxes, add the email to the first one get the index where you added and add the next bit of info into the second one at the same index from the first listbox. If you remove an item in the first one you need to get the index and remove the same index in the second listbox, this way you synchrinse the listboxes.

please can you show me how to do that
look at the code earlier please

OK, but I can just see one listbox in your code. So I just give you a rough idea:
Your existing code:

If Not Len(Trim(rs("Email1"))) = 0 Then LstData3.AddItem rs("Email1") & " " & rs("eftn") & " " & rs("namn")

Ok, now lets assume you have 3 listboxes, LstData4,LstData5
then you want to clear these so the index starts at 0
and you would do something like:

If Not Len(Trim(rs("Email1"))) = 0 Then
LstData3.AddItem rs("Email1")
LStData4. AddItem rs("eftn")
LstData5.AddItem rs("namn")
end if

as you say it works fine
but one major problem is there.

lstdata3 looks like this lstdata4 looks like this- lstdata5 like this
danielenn@comhem.se Butabayeva Anne

it's not the way i will have it

bahad@mailru Butabayeva Anne
danielenn@comhem.se Daniel Lenny

and so on for all the email's

I will have say lstdata3 = email lstdata4= surename lstdata5= forename

bahad@mail.ru connected to        Butabayeva           Anne

and so on for just those people that have there email adress nothing else

If you get the samedata in each listbox you need to check how you retrieve the data. Where is your data stored in?

mdb

Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\PhoneTel.mdb")
Set rs = db.OpenRecordset("Phone", dbOpenTable)

OK, did you check the data you are returning? You can use something like debug.print("Your Data") to see what your loop is returning. Nake sure the data is stored correctly in your database - open it with access and have a look. I will check later that you use the correct code - from memory there is something like an index, like LstData3.AddItem rs("Email1",0) - check it and I will get back.

Hi

I have check it out and I can't find like LstData3.AddItem rs("Email1",0).
have a look at the database picture

Well looking at the second picture I can see thet you are not retrieving the data correctly or it is strored incorrectly.

Hi and Happy New Year

i have get this and it will be with the numbers to left

 For i = 1 To max

   entry = i & "      " & rs("email")
   temp = rs("email1")

     If Not Len(Trim(entry)) = 0 Then LstData3.AddItem entry
     'If Not Len(Trim(temp)) = 0 Then LstData3.AddItem temp
     'If Not Len(Trim(rs("email"))) = 0 Then List2e.AddItem rs("namn")


    rs.MoveNext


    Next

and it will not be sorted as I would like the email is comming
according to the numbers of I

Happy New Year to You too.

From what I see you use trhe i as a counter but set it up like a loop.
Just dim it outside your record retrieval and than add 1 to it :

dim icounter as Integer
'Check if the recordset contain records'
If Not rs.RecordCount=0 Then
'Move to the first record'
   rs.MoveFirst
'Loop till the recordset return EOF(end of file)'
   While Not rs.EOF
     'do some stuff here'
'Move to the next record'
      rs.MoveNext
      iCounter = iCounter + 1
   Wend
End If

Also check this one out:
http://visualbasic.freetutes.com/learn-vb6/lesson4.html

Thanks

But I did not get it right i any case att all.
It fills the list box with ten of same emails.(listimage2)

listimage3 to the left is okej but the surenames should come in list1e
exactly as the are in listimage3. as the code submitted

     Dim icounter As Integer
    'Check if the recordset contain records'
    If Not rs.RecordCount = 0 Then
    'Move to the first record'
    rs.MoveFirst
    'Loop till the recordset return EOF(end of file)'
    While Not rs.EOF
    ' For i = 1 To max


entry = rs("email")
temp = rs("eftn")
If Not Len(Trim(entry)) = 0 Then LstData3.AddItem entry & temp
If Not Len(Trim(entry)) = 0 Then List1E.AddItem temp
'If Not Len(Trim(rs("email"))) = 0 Then List2e.AddItem rs("namn")


    'do some stuff here'
    'Move to the next record'
    rs.MoveNext
    icounter = icounter + 1
    Wend
    End If

Hi

look at the image

Hi

I have been thinking that the list1e is sorting after EFTN and email i sorted after EMAIL.

any help

O.K. let's take it bit by bit. First check that the loop works and returns the correct entries. Rem everything out but the stuff that returns the strings. Dimension the strings correctly and we check that the counter works. Print everything to debug.

Dim icounter As Integer
    Dim entry as String
    Dim temp as String
    iCounter=0
    'Check if the recordset contain records'
    If Not rs.RecordCount = 0 Then
    'Move to the first record'
    rs.MoveFirst
    'Loop till the recordset return EOF(end of file)'
    While Not rs.EOF
    ' For i = 1 To max
entry = rs("email")
Debug.print(entry)
temp = rs("eftn")
Debug.print(temp)
'If Not Len(Trim(entry)) = 0 Then LstData3.AddItem entry & temp
'If Not Len(Trim(entry)) = 0 Then List1E.AddItem temp
'If Not Len(Trim(rs("email"))) = 0 Then List2e.AddItem rs("namn")
    'do some stuff here'
     icounter = icounter + 1
     Debug.print(iCounter)
    'Move to the next record'
    rs.MoveNext

    Wend
    End If

O.K. let' assume you got all the correct data. You now have to look at the data you add. If temp is empty, what you do than?
You add data to the first listbox, but nothing to the second. So if the next data comes along you add it to the first listbox at an index that will be different from the index in the second listbox. So if temp=" " then add something like Temp= "----", that will avoid the distortion of added entries.

Now in regards to your sorting, obviously you only can sort by one listbox at the time. So you add the first item to the listbox you want your data sorted by. You get the index of where the item is added and than you insrt the items in the other listboxes at this index.

It stops first time at line 14
and when I put the string temp="----" it whent
with no problem

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.