• find a record in a list

    • This topic has 3 replies, 3 voices, and was last updated 24 years ago.
    Author
    Topic
    #355240

    Choose an order number in a list box from a control box.

    I want to find an order number in the list box by typing the number of the order in a control box.
    I want by typing the number of the order to go to the that particular order in the list box.
    However i cannot do it.The name of my List Box is CboOrder and each order number within the list

    box is an Integer.The form containing the list box is called Form1. I have build the following

    code however it seems it is totally wrong and i have bungled everything. Could somebody help me out

    of that mess?

    Dim strOrderID As String
    Dim Order as control
    set OrderID = Forms![Form1]![CBoOrder]
    Dim strBookmark As String
    strBookmark = Forms![Forms1![CboOrder].Bookmark
    strOrderID = InputBox(“Please enter OrderID number “)
    OrderID.RecordsetClone.FindFirst “OrderID = ” & strOrderID
    If OrderID.RecordsetClone.NoMatch Then
    MsgBox “OrderID ” & strOrderID & ” Not Found!!”
    OrderID.Bookmark = strBookmark
    Else
    OrderID.Bookmark = OrderID.RecordsetClone.Bookmark
    End If

    Viewing 0 reply threads
    Author
    Replies
    • #523599

      A few possible problems that caught my eye are:
      1) Syntax problem in the line:

      strBookmark = Forms![Forms1![CboOrder].Bookmark

      It should read:

      strBookmark = Forms![Forms1]![CboOrder].Bookmark

      (Note the added “]” after [Forms1])

      2) If your strOrderID is a String value, then your FindFirst statement should reflect that data type:

      OrderID.RecordsetClone.FindFirst "OrderID ='" & strOrderID & "'"

      (Notice the added Single Quotes to indicate a String value rather than a numeric value.)

      HTH thumbup

      • #523621

        Dear Sir,

        Thank you very much for your reply.What i want is by entering the order number do go directly to that order number in the list box.This is very important to
        me and i will be really grateful if you can help me.Is it possible that i send to you the zipped database?
        It will be only 100 KB.By looking in the real form you might give me some precious recommendations.If you would agree will you let me know the adress where to send

        Best regards
        P.S, becasue of some other reasons i will ned a lsit box and not a
        combo box or a subform.

        • #523676

          Are you typing the value in a textbox and then you want to have the cursor position itself in a listbox with that value selected? The code you posted is for finding a record within a recordset, not for selecting an item in a listbox. If what you’re trying to do is just select a particular item in a listbox, here’s a method:

          Public Sub SelectListboxItem(lst As ListBox, _
                                      varValue As Variant)
            'Created by Charlotte Foust 4/22/2001
            Dim intIndx As Integer    'holds the row index of the listbox
          
            'Example:    SelectListboxItem .Value
            
            'loop through the rows to find the
            'one that matches the  value
            For intIndx = 0 To lst.ListCount - 1
              If lst.ItemData(intIndx) = varValue Then
                'when a match is found, set that
                'row's selected property to true
                'and exit the For loop
                lst.Selected(intIndx) = True
                Exit For
              End If ' lst.ItemData(intIndx) = varValue
            Next intIndx '= 0 To lst.ListCount - 1
          End Sub 'SelectListboxItem(lst As ListBox, _
                            varValue As Variant)
    Viewing 0 reply threads
    Reply To: find a record in a list

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: