Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i want to display the items of list view into a message box in vb 6.0

VB
Private Sub Command1_Click()
CN.Open "Driver=sql server;server=SOFT2;DataBase=Timetronix;"
MsgBox "connect to the database"
REC.Open "Select * from CHECKINOUT where CHECKTIME BETWEEN '" & DTPicker1.Value & "' AND '" & DTPicker2.Value & "'", CN, adOpenStatic, adLockReadOnly

If REC.RecordCount > 0 Then
For i = 1 To REC.RecordCount
            LstLog.ListItems.Add , , REC("SensorID")

            LstLog.ListItems(i).SubItems(1) = REC("CheckTime")

            LstLog.ListItems(i).SubItems(2) = IIf(IsNull(REC("EMPID")), "", REC("EMPID"))
            REC.MoveNext
            Next
            REC.Close
            CN.Close
            End If
MsgBox "hello" & LstLog.listitems
End Sub




The problem is that data is coming from data base but i can't able to display them in message box..
Posted
Comments
Nawab Ahmad 29-Jun-13 7:08am    
Hi,
thank but the problem with this code the message is display row by row ..means once the data come from database in sit in the first row of the listview suddenly msg is generated with the first row then wen u click ok the data willl come and sit in secon row of listview ........
Aydin Homay 30-Jun-13 0:25am    
Ok tell me what you want exactly ? what is your requirement ?

Hi please pay attention to:

VB
Collapse | Copy Code
Private Sub Command1_Click()
CN.Open "Driver=sql server;server=SOFT2;DataBase=Timetronix;"
MsgBox "connect to the database"
REC.Open "Select * from CHECKINOUT where CHECKTIME BETWEEN '" & DTPicker1.Value & "' AND '" & DTPicker2.Value & "'", CN, adOpenStatic, adLockReadOnly

If REC.RecordCount > 0 Then
For i = 1 To REC.RecordCount
            LstLog.ListItems.Add , , REC("SensorID")

            LstLog.ListItems(i).SubItems(1) = REC("CheckTime")

            LstLog.ListItems(i).SubItems(2) = IIf(IsNull(REC("EMPID")), "", REC("EMPID"))
MsgBox "hello " &  LstLog.ListItems(i)
            REC.MoveNext
            Next
            REC.Close
            CN.Close
            End If

'Or you can use  LstLog.ListItems(i) & LstLog.ListItems(i).SubItems(1) & LstLog.ListItems(i).SubItems(2)
End Sub


and if you want getting information about message box in vb6 you can follow of links:
http://visualbasic.freetutes.com/learn-vb6/lesson18.html[^]
http://www.vb6.us/tutorials/understanding-msgbox-command-visual-basic[^]
Best Regards.
 
Share this answer
 
v5
Comments
Nawab Ahmad 29-Jun-13 6:14am    
Hi,
thnk for ur replly but geting Runtime Error '35600' index out of bound.
Aydin Homay 29-Jun-13 6:32am    
Oh so sorry you right I changed it ;) check it again
Try this :

VB
Dim str As String

For Each itm in LstLog.ListItems
   str=str & itm
Next

MsgBox("Hello " & str & " ")
 
Share this answer
 
v2
Comments
Nawab Ahmad 29-Jun-13 6:17am    
Hi,

this is working but displaying only the first column items....
VB
Dim str As String
For Each col in LstLog.Columns
  For Each itm in LstLog.ListItems
     str=str & itm
  Next
Next

MsgBox("Hello " & str & " ")
 
Share this answer
 
Comments
Aydin Homay 29-Jun-13 6:32am    
For Each in vb6 ? !!!
Nawab Ahmad 29-Jun-13 6:37am    
Hi,

Thanks again but still it is printing the items of first column only..

i have the column 1.empid 2.checkindate 3.mechine id

so empid=1,2,3,4,5,........etc

so,it is printing only empid column onlyin msgbox....
and it want msg should be 1 2/02/2013 3
2 5/2/2013 3...etc
Aydin Homay 30-Jun-13 0:27am    
you can use my comment code in solution:

LstLog.ListItems(i) & LstLog.ListItems(i).SubItems(1) & LstLog.ListItems(i).SubItems(2)
jenitshah 29-Jun-13 6:40am    
Sorry, I have no any further idea on it.
Nawab Ahmad 29-Jun-13 7:11am    
Hi,

you know how set the time to execute query in vb 6.0.

example : i have writen one query in command1
and i want that command1 automatic execute every day at sharp 9:00 am.
plz reply..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900