Determining selection in unbound list box

jess

New member
Local time
Today, 13:34
Joined
Aug 16, 2002
Messages
5
Ok, here's the deal. I have an unbound list box that is displaying the results of a Query on my main table of data. This data can easily be browsed in tabular form by the users.

When the user double-clicks on an item from the list box, I have an event procedure that pops up detailed information for that item. What I need to know is how to determine what item has been selected within the unbound list box. From that selection, I need to extrapolate the ID number to compare it to the IDs from the detailed info.

With this information, I can open the detailed information window up to the correct record. I would prefer a VBA solution to the problem.

Here's what I have and what I need:

Private Sub List18_DblClick(Cancel As Integer)

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "View_Edit_Action_Item"

stLinkCriteria = "[ID]=" & "'" & Me![ID] & "'" <-- This is wrong, because it defaults to the ID that is selected by the whole form, rather than the selection within the unbound list box
DoCmd.OpenForm stDocName, , , stLinkCriteria

End Subwhole form

A little help with that LinkCriteria line would be much appreciated!

Jess
 
You need to refer to the name of the listbox control on your form, instead of the form itself; i.e.:

[ID] = [Forms]![View_Edit_Action_Item]![yourlistboxname]

It will refer to the currently selected item in the listbox.

Cheers
 
This is helpful in that it allows me to refer to the unbound list box's current selection. However, I still am not able to extrapolate the ID number from the selection. In order to display the correct information detail when the new window pops up, I have to have some way of comparing the current selection with the table of data and drawing up the correct information. Having a unique ID for each data member has worked great thus far, but I have not been able to determine the ID number of the current selection in the unbound list box, and thus, I am unable to make any comparisons to draw up the correct record.

It is highly likely that I am making this more difficult than it has to be. If there is an easy way to perform the same function as my unbound list box filled with a query to display data, I'd love to hear it! It appears that I am unable to extract the ID from the unbound list box since it only displays the results of a query.

Is this correct? Any further assistance would be appreciated.

Jess
 
Okay, tell me what columns you have in your listbox - [ID] should be the bound column.
 
I'm not sure what you mean by bound column. The listbox displays eight columns across with Information from ID numbers to dates and other such stuff. When you click inside of the listbox, you end up selecting one row, a row containing multiple values. Also [Forms]![View_All_Action_Items]![List18]![ID] does not work for drawing out the [ID] field of the current row selected.

Jess
 
Great! Setting ID to the bound column worked! Thanks a bunch.

Jess
 

Users who are viewing this thread

Back
Top Bottom