Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    find a record in a list

    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

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: find a record in a list

    A few possible problems that caught my eye are:
    1) Syntax problem in the line:<pre>strBookmark = Forms![Forms1![CboOrder].Bookmark</pre>

    It should read:<pre>strBookmark = Forms![Forms1]![CboOrder].Bookmark</pre>

    (Note the added "]" after [Forms1])


    2) If your strOrderID is a String value, then your FindFirst statement should reflect that data type:<pre>OrderID.RecordsetClone.FindFirst "OrderID ='" & strOrderID & "'"</pre>

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

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: find a record in a list

    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.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: find a record in a list

    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:

    <pre>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 [list].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)</pre>

    Charlotte

Posting Permissions

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