Im using listbox with style = 1-checkbox. "project.mdb" is the database name "goods" is the table name.
"tabno" and "tabid" are fields in the table.

dim d as database
dim table as recordset
dim b as integer
dim c as integer

Private Sub Form_Load()

Set d = OpenDatabase(App.Path & "\" & "project.mdb")
Set table = d.OpenRecordset("goods")
table.MoveLast
c = table!tabno
table.MoveFirst
b = table!tabno
Do While (b < c + 1)
List1.AddItem (table!tabid)
table.MoveNext
b = b + 1
Loop
End Sub

what I want is,when running application if I check any checkbox and click command button,then the tabid and tabno related to selected check box should desplay in a textbox.
hope any help..thank you

Recommended Answers

All 5 Replies

Create an array and put it in the loop, such that for every item in the list you have a corresponding tabno in from the array.

Try This :

Public Conn As New ADODB.Connection
Private Sub Access_Connector()
    Set Conn = New ADODB.Connection
    Conn.Provider = "microsoft.jet.oledb.4.0"
    Conn.CursorLocation = adUseClient
    Conn.Open App.Path & "\project.mdb"
End Sub
Private Sub GetData()
    Set rs = New ADODB.Recordset
    rs.Open "SELECT * from goods ", Conn, adOpenDynamic, adLockBatchOptimistic

    While Not rs.EOF
        List1.AddItem rs.Fields("tabid")
        rs.MoveNext
    Wend
    rs.Close
End Sub

Private Sub Command1_Click()
    Dim temp As String
    Text1.Text = ""
    For i = 0 To List1.ListCount - 1
        If List1.Selected(i) = True Then
            temp = temp & List1.List(i) & ","
        End If
    Next

    Set rs = New ADODB.Recordset
    rs.Open "SELECT * from goods where tabid in (" & temp & ")", Conn, adOpenDynamic, adLockBatchOptimistic

    While Not rs.EOF
        Text1.Text = Text1.Text & rs.Fields!tabid & "-" & rs.Fields("tabno") & vbCrLf
        rs.MoveNext
    Wend
    rs.Close
End Sub

Private Sub Form_Load()
Access_Connector
GetData
End Sub

Nice JX_Man, as always you showed the exact and to the point code. :)

commented: Thank you :) +13

sorry for late due to bad connection.:( .thank you very much I will try this and let you know.

If it worked for you, please mark as solved, thanx. We do not want any open threads that gave you a solution to a 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.