Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Posts
    1

    Unanswered: Finding an entry in a listbox

    Okay. I'm having some problems getting a listbox to work as I wish it to. My problems are as follows:

    The listbox is filled by the results of a query. Initially, the listbox contains a full list of every entry that can be queried (that is, no criteria has been used to filter the results of the query yet, so all of the entries are shown), and therefore the order of the entries in the listbox corresponds exactly to the order that the entries are found in their table.

    Naturally, once a query is run, and the listbox refreshes the number of entries that it lists, the number of these entries will decrease as entries are filtered away by search criteria: unfortunately, their order in the listbox will now no longer correspond to that of the table. This is a problem because I wish to have the listbox results able to be doubleclicked by the user and then bring up that entry in another form. But since the only way I have of knowing which entry has been doubleclicked is by looking at which number the entry is in the listbox, the wrong entry will appear in the form when the listbox eliminates entries because of a search.

    Here's the code I am using, it might demonstrate the situation better:

    If Not IsNull(Me![lstQueryBox].Column(0)) Then
    varValue = Me![lstQueryBox]
    End If

    For X = 0 To 50 //50 is arbitrary since the number of entries won't be exceeding 50.
    If varValue = lstQueryBox.Column(0, [X]) Then
    DoCmd.Close
    DoCmd.OpenForm "frmResourceCatalog", acNormal
    DoCmd.GoToRecord , , acGoTo, X[/i]//Here's the problem. I need the number of the selected entry as it is order in the table, not the listbox[/i]
    GoTo Quit_Sub
    End If
    Next X
    If you have any suggestions on how to code this differently so as to find, not just the entry's number in the listbox but in the table, I would weep with delight. I haven't been able to find anything useful browsing through the sdk, and that's pretty much become my last refuge of assistance when I'm running from a problem.

    Thanks in advance,

    Travis

  2. #2
    Join Date
    Aug 2002
    Location
    England
    Posts
    1

    Re: Finding an entry in a listbox

    I use a ListBox called lstContacts to show selected items from a query. I have a Double_Click event procedure for the ListBox that contains the following code:

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmContact"

    If IsNull(lstContacts.Value) Then
    MsgBox "No Record Selected"
    Else
    If Ns(lstContacts.Column(0)) = "" Then
    MsgBox "No Record Selected"
    Else
    stLinkCriteria = "[CaseNumber]=" & lstContacts.Column(0) & " and [Id]=" & lstContacts.Value
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If
    End If

    stLinkCriteria builds a WHERE condition using data from the ListBox and this is passed to the form when it is opened.

    I hope this helps.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •