By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,469 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,469 IT Pros & Developers. It's quick & easy.

Showing data in a listbox (two fields)

P: 9
I would like to know if theres a possible way to show two fields in a listbox. Right now i show one field of a table in the listbox (the values showed on the listbox depend on what the user type in a textbox), but i would like to show two fields of the same table in the same listbox, for example:
I have a table called "Tools" and the fields are Code, Grade, Description, Amount, Price, Total, Location. I would like to show the fields Code and Grade in the same ListBox.

Is this possible?, If it can be done, how can i do it?

Thanks!
Dec 22 '06 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
I would like to know if theres a possible way to show two fields in a listbox. Right now i show one field of a table in the listbox (the values showed on the listbox depend on what the user type in a textbox), but i would like to show two fields of the same table in the same listbox, for example:
I have a table called "Tools" and the fields are Code, Grade, Description, Amount, Price, Total, Location. I would like to show the fields Code and Grade in the same ListBox.

Is this possible?, If it can be done, how can i do it?

Thanks!
1. Create a query with the two fields and set listbox Row Souce to query.
2. Set Column Count property to 2
3. Set Column Width property to e.g. 3cm;3cm
4. Make sure the Bound column property is set to the column containing the value you want stored or used.

Merry Christmas


Mary
Dec 25 '06 #2

P: 9
I have a table called "Tools" and i want to modify a register of that table, for that, i need that the user "select" the register that needs to be modified. To do this, i put three text boxes (txtCode, txtGrade, txtDate) and a listbox; if i want that depending on what the user write in each one of the text boxes, the data that belongs to that criteria shows on the listbox; what should i do?

At this moment i have a code that allows me to do that but just with one textbox adn selecting the field of the table from a combo box; this is the code:

----------------------------------listbox ---------------------------------------------------------------

Private Sub lstResultado_AfterUpdate()
Dim rst As Object

On Error GoTo lstResultado_AfterUpdate_Error

Set rst = Me.Recordset.Clone

rst.FindFirst "ID = " & Me.lstResultado.Column(1)

If Not rst.NoMatch Then Me.Bookmark = rst.Bookmark

rst.Close
Set rst = Nothing

lstResultado_AfterUpdate_Salir:
On Error GoTo 0
Exit Sub

lstResultado_AfterUpdate_Error:

MsgBox "Error " & Err.Number & " en proc.: lstResultado_AfterUpdate de Documento VBA: Form_frmProveedores (" & Err.Description & ")"
GoTo lstResultado_AfterUpdate_Salir
End Sub
-------------------------------------------------------------------------------------------------------------

------------------ textbox -------------------------------------------------------------------------------

Private Sub txtBusqueda_Change()
Dim strSQL As String

strSQL = "SELECT " & Me.cmbCampo & ", ID "
strSQL = strSQL & "FROM ComprasConsumibles "
strSQL = strSQL & "WHERE [" & Me.cmbCampo & "] LIKE '*" & txtBusqueda.Text & "*'"

Me.lstResultado.RowSource = strSQL
End Sub

--------------------------------------------------------------------------------------------------------------
Dec 27 '06 #3

P: 9
i have answered my doubt, the code is:

Private Sub txtCode_Change()

Dim strSQL As String

strSQL = "SELECT Codigo, Grado, ID "
strSQL = strSQL & "FROM Consumibles "
strSQL = strSQL & "WHERE [Codigo] LIKE '*" & txtCode.Text & "*'"
strSQL = strSQL & "AND [Grado] LIKE '*" & txtGrade & "*'"

Me.lstMatch.RowSource = strSQL

End Sub

---------------------------------------------------------------------------------------------------------

Private Sub txtGrade_Change()

Dim strSQL As String

strSQL = "SELECT Codigo, Grado, ID "
strSQL = strSQL & "FROM Consumibles "
strSQL = strSQL & "WHERE [Grado] LIKE '*" & txtGrade.Text & "*'"
strSQL = strSQL & "AND [Codigo] LIKE '*" & txtCode & "*'"

Me.lstMatch.RowSource = strSQL

End Sub
Dec 28 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.