Opening a form and automatically selecting a record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • limperger
    New Member
    • Mar 2008
    • 66

    Opening a form and automatically selecting a record

    Hello everyone!

    Just in case anyone here has experienced this problem and knows how to deal with it:

    I have 2 forms from 2 related tables. We have more than 600 records in the first one and of these, 150 also appear in the second table.
    We work with the form of the principal table (that is, the one with 600 records). In it, I've got a field that indicates whether the particular record selected is also present in the second table. A sum-up subform is also present, just to get the idea of the data for that record in the second form. Nevertheless, I have also included a command button that launches the second form, just in case some data may be added. My question is the following one: is it possible to launch the second form in a way that the record selected in the first form is the record that appears selected when launched this second form?? That is, if I've got selected (from a list box) the record AAA in the first form and I know it appears in the second one (so I launch it), is it possible that when the second form opens, the record I was working with is already selected??

    Best regards!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32645

    #2
    Luckily enough, the answer to this doesn't depend on the rest of the explanation :D

    When opening a form in VBA code you use the code :
    Code:
    Call DoCmd.OpenForm(FormName, _
                        View, _
                        FilterName, _
                        WhereCondition, _
                        DataMode, _
                        WindowMode, _
                        OpenArgs)
    The last parameter is what you're interested in. In your situation I expect you'd need the key of the record passed in here.

    NB. When referencing Me.OpenArgs in your Form_Open() procedure make sure you do it first thing. This property is cleared when any other code is run. Often saving it to a separate variable for safe-keeping is a good idea.

    Comment

    • limperger
      New Member
      • Mar 2008
      • 66

      #3
      NeoPa:

      Thank you very much for your help. I will proceed as suggested.

      Bets regards

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32645

        #4
        No worries & Good Luck :)

        Comment

        • limperger
          New Member
          • Mar 2008
          • 66

          #5
          Thanks NeoPa!!

          Bets regards

          Comment

          Working...