SearchForRecord function problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anansi
    New Member
    • Nov 2006
    • 15

    SearchForRecord function problem

    Hi all

    I have a very simple problem but i am highly confused. firstly, a google web search of "DoCmd.Searchfo rrecord" returns nothing. i've been starting to get suspicious why no one else is interested in this function but me, but here goes:

    Code:
    sID = Me.ShiftID                   '--- this is the subforms field, ShiftID
    ParentsID = Me.Parent.ShiftID          '---this is shift viewer's field, ShiftID
    DoCmd.SearchForRecord acDataForm, "shift viewer", , (ParentsID = sID)
    I am under the impression, that my form, "shift viewer" will goto the first record which has a ShiftID of Me.ShiftID (Me being the subform)

    i tried putting a breakpoint, on the 3rd line (DoCmd...) and noticed that the values of sID and ParentsID are both as they should be before i do the 3rd line, but when the 3rd line executes, the form "shift viewer" (very quickly, in like 1/4 of a second) runs through all its records, doesnt find the record where the condition is met ( parameter 4) and returns to the record it was originally on... what am i doing wrong?

    thanks in advance
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by anansi
    Hi all

    I have a very simple problem but i am highly confused. firstly, a google web search of "DoCmd.Searchfo rrecord" returns nothing. i've been starting to get suspicious why no one else is interested in this function but me, but here goes:

    Code:
    sID = Me.ShiftID                   '--- this is the subforms field, ShiftID
    ParentsID = Me.Parent.ShiftID          '---this is shift viewer's field, ShiftID
    DoCmd.SearchForRecord acDataForm, "shift viewer", , (ParentsID = sID)
    I am under the impression, that my form, "shift viewer" will goto the first record which has a ShiftID of Me.ShiftID (Me being the subform)

    i tried putting a breakpoint, on the 3rd line (DoCmd...) and noticed that the values of sID and ParentsID are both as they should be before i do the 3rd line, but when the 3rd line executes, the form "shift viewer" (very quickly, in like 1/4 of a second) runs through all its records, doesnt find the record where the condition is met ( parameter 4) and returns to the record it was originally on... what am i doing wrong?

    thanks in advance
    The FindRecord method carries out the FindRecord action in Visual Basic.

    expression.Find Record(FindWhat , Match, MatchCase, Search, SearchAsFormatt ed, OnlyCurrentFiel d, FindFirst)
    expression Required. An expression that returns one of the objects in the Applies To list.

    FindWhat Required Variant. An expression (expression: Any combination of mathematical or logical operators, constants, functions, and names of fields, controls, and properties that evaluates to a single value. Expressions can perform calculations, manipulate characters, or test data.) that evaluates to text, a number, or a date. The expression contains the data to search for.

    Match Optional AcFindMatch.

    AcFindMatch can be one of these AcFindMatch constants.
    acAnywhere
    acEntire default
    acStart
    If you leave this argument blank, the default constant (acEntire) is assumed.


    MatchCase Optional Variant. Use True for a case-sensitive search and False for a search that's not case-sensitive. If you leave this argument blank, the default (False) is assumed.

    Search Optional AcSearchDirecti on.

    AcSearchDirecti on can be one of these AcSearchDirecti on constants.
    acDown
    acSearchAll default
    acUp
    If you leave this argument blank, the default constant (acSearchAll) is assumed.


    SearchAsFormatt ed Optional Variant. Use True to search for data as it's formatted and False to search for data as it's stored in the database. If you leave this argument blank, the default (False) is assumed.

    OnlyCurrentFiel d Optional AcFindField.

    AcFindField can be one of these AcFindField constants.
    acAll
    acCurrent default
    If you leave this argument blank, the default constant (acCurrent) is assumed.


    FindFirst Optional Variant. Use True to start the search at the first record. Use False to start the search at the record following the current record. If you leave this argument blank, the default (True) is assumed.

    Remarks
    For more information on how the action and its arguments work, see the action topic.

    You can leave an optional argument blank in the middle of the syntax, but you must include the argument's comma. If you leave one or more trailing arguments blank, don't use a comma following the last argument you specify.

    Example
    The following example finds the first occurrence in the records of the name Smith in the current field. It doesn't find occurrences of smith or Smithson.

    DoCmd.FindRecor d "Smith",, True,, True

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32666

      #3
      The procedure DoCmd.SearchFor Record doesn't exist in Access (Not that I could find any reference to anyway).
      ADezii's post gives full information on how to do what you're after.
      I hope this resolves your problem.

      Comment

      • anansi
        New Member
        • Nov 2006
        • 15

        #4
        Yes this is what i want to do, thank you

        Since the information was posted i'v been trying to get it all to work. i am failing miserably.. The DoCmd needs to be for the parent of the subform and i cant seem to access the necessary form "shift viewer". The "shift viewer" form is what needs to FindRecord.

        So my question isn't about FindRecord anymore, but about getting to the Form, "shift viewer", and being able to perform the method, FindRecord

        for example,
        Code:
        AllForms![shift viewer].Application.FindRecord Me.ShiftID, , True, , True
        tells me "Object Required". quite confusing

        thanks a lot in advance

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32666

          #5
          Look in this Tutorial for help on (Referring to Items on a Sub-Form).
          Let us know how you get on :)

          Comment

          • anansi
            New Member
            • Nov 2006
            • 15

            #6
            Originally posted by NeoPa
            Look in this Tutorial for help on (Referring to Items on a Sub-Form).
            Let us know how you get on :)
            hey. i tried, but am going to try another algorithm.. my problem is that i can accomplish the addressing between the form and subform, but when i try do a DoCmd.FindRecor d it does it for the subforms "record set" (not sure if i mean record set), where i actually want the action to be performed on the main form's "record set". switching the focus doesnt help, and i simply dont know why nothing wants to work...

            thanks guys

            Comment

            Working...