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

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

Edited 4 Years Ago by Jx_Man

Attachments Untitled.jpg 14.28 KB

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

Edited 4 Years Ago by mahela

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. :)

This article has been dead for over six months. Start a new discussion instead.