问题
I have a listbox in Access 2007 that is linked to a table. That table has 4 columns but I only have 2 of those columns visible in the listbox. I use the loop command to identify the selected row but I can only view the contents of the visible columns. I display the visible column when I find it so at least I know I have the right row. It is my belief that the other 2 hidden columns are technically available to me because I see them referenced when I view the SQL associated to the listbox. So I have 2 related questions:
How can I confirm that those 2 hidden columns are actually available to me? And how can I access them (I want to get the primary key associated to the row selected.)
If those hidden columns are available and I wanted to make them visible in the listbox, how would I do that?
Learning Access is now a weekend hobby.Thanks in advance. DaveL
回答1:
You can make a listbox show whatever you would like. When you have it selected in design view then open the property sheet and select the Format tab. Where it says column count and column widths is where you can modify the obvious. The Data tab on the property sheet will allow you to select all 4 of your fields to appear in the listbox.
Now to use the data in that listbox, you can use the VBA for click() and choose which column you want to work with if you have the primary key associated with that listbox.
Public Sub The_Listbox_Click()
Dim myR as Recordset
Set myR = CurrentDb.OpenRecordset("Table_Name", dbOpenDynaset)
myR.FindFirst ("[Primary_Key_Field] = '" & Me.The_Listbox.Column(0) & "'")
'You can now use that record with myR![Field_Name]
Set myR = Nothing
End Sub
来源:https://stackoverflow.com/questions/17254524/hidden-column-in-listbox-access-2007