Results 1 to 6 of 6

Thread: findfirst

  1. #1
    Join Date
    Oct 2012
    Posts
    56

    Unanswered: findfirst

    I have a button on a main form that I use to populate a query with an underlying table. I want to prevent the user clicking the button more than once and populating the query with a duplicate set of records. So I want to use the findfirst to see if the records are already there. so

    code
    If rsPurchDetail.findfirst "[Catergory] = " & Bar Liquor then
    Do something
    rsPurchDetail.Nomatch Then
    Do something else
    End If

    Need some help with the syntax

    Thanks Bob

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    It should be something like:
    Code:
    rsPurchDetail.findfirst "[Catergory] = 'Bar Liquor'"
    If rsPurchDetail.Nomatch = False Then ' Found.
        ' Do something
    Else                                  ' Not found.
        'Do something else
    End If
    Have a nice day!

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If your problem is. users pressing the same button twice then id disable the button after the first push. You would also need to have a mechanism to re enable the button if required.

    I think you`d need to switch the focus away from the button before disabling it ysing the setfocus property of another control.

    I think its rhe enabled property yiu`d need to set to false.

    Having said that queries are not additive. Either the query holds something or it doesnt. You cant run the same query more than once and get multiple rows of the same data.
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Oct 2012
    Posts
    56

    Thanks almost there

    The code you gave me worked great but on the entire recordset and I want only the records linked to the main form.

    Code:
    -----------------------------------
    RecPurchDetailAll.FindFirst "[Catergory] = 'Bar Liquor'" And '"[TransID] = lngMainKey"'"
    If RecPurchDetailAll.NoMatch = False Then
    MsgBox "Items Have Already Been Added", vbOKOnly, "Validate Data"
    Cancel = True
    Me.CboSupplier.SetFocus
    Exit Sub
    Else
    --------------------------------------
    lngMainKey is a variable that captures the Primary key of the main form

    Thanks Bob

  5. #5
    Join Date
    Oct 2012
    Posts
    56

    Problem no resolved but an alternate used

    Hi all thanks for the help given but was still unable to solve the findfirst with two criteria. After three frustrating days I give up and looped through the recordset checking for the two criteria if it found a match then it exited the sub if not it carried on and did the insert

    Bob

    Ps lot of people looking for a solution to this problem

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    as said before when you run a query the results are not additive, a recordset from a query contains ONLY those rows in that query.
    what I suspect you are doing is adding those rows to controls on a form.

    again as said before a smarter call in my books is to disable the button after the user has pressed it. avoids any matching, it stops the user pressing the button twice. you will need some other code elsewhere to re enable the button when that is appropriate

    the whole pont of moving to a windowing user interface is that users should be able to press whatever buttons they like in whatever order they like. if the user doing something
    can cause problems then don't let them do that, rahter than check after the event.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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