Is it Possible to Reference a SubForm in DoCmd.SearchForRecord?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32645

    #16
    From Referring to Items on a Sub-Form, you could also shorten it a little further with :
    Code:
    Forms!frmLoans.sfrmAppraisals!Recordset.FindFirst "AppraisalID = " & Me.txtAppraisalID
    This is example of appreciating where dot and bang make most sense.

    I would also suggest that if you are going to use this new procedure for the subform (and there's really no reason why you wouldn't), then it would makes sense to use that same procedure for the other form too - to provide consistentcy.
    Code:
    Private Sub Command4_Click()
        DoCmd.OpenForm "frmLoans"
        With Forms!frmLoans
            .Recordset.FindFirst "LoanID = " & Me.txtLoanID
            .sfrmAppraisals!Recordset.FindFirst "AppraisalID = " & Me.txtAppraisalID
        End With
    End Sub
    Last edited by NeoPa; Dec 11 '12, 05:45 PM. Reason: Added example code.

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #17
      So the procedure for the other form would be

      Code:
      Forms!frmLoans.Recordset.FindFirst "LoanID =" & Me.txtLoanID
      I get an error saying "can't find the field 'Recordset'" when I take the .Form out from before it. I tried . instead of !, but that broke it as well (as you probably already knew).
      Last edited by Seth Schrock; Dec 11 '12, 05:43 PM. Reason: Added Error

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32645

        #18
        I think I was editing and improving my post as you were testing that Seth. Can you try the code as it is now (in post #16) and tell me what errors you get, if any. You need to be clear which lines you're talking about when reporting that, of course.

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #19
          I get the same error message(Microso ft Access can't fin the field 'Recordset' referred to in your expression) on your line 5.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32645

            #20
            Very strange. What do you get if you try :
            Code:
            .sfrmAppraisals.Form.Recordset.FindFirst "AppraisalID = " & Me.txtAppraisalID
            Maybe the ! shortcut only works for controls on the form. I've never had to use the .Form. syntax before.

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #21
              That works great. That is also the same as what I had before only in With/End With form (which I like as it is neater).

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32645

                #22
                A new thread - Discussion: Dot Versus Bang (Again) - has been created to handle the discussion that developed from looking for the best answers for this question.

                Comment

                Working...