Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Dec 2002
    Location
    Kitchener, Ontario, Canada
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set focus to new record (2003 SP3)

    I have two forms A & B. From A, I open Form B, copy information from A and paste it into B including creating the first record on a subform on B. The info in the first record is from A. I am creating a family grouping, starting from the head of the family (on form A). The family name is created on the main form of B ("Smith Family") then the head of the family is the first record ("John Smith") on the subform, which is a continuous form. What I want to do is set the cursor to the next record on the subform so that the remaining family members can be added.

    After the first family record is created, there is some further code on the first form, so I am assuming I have to create the new record on form B from Form A. Is this possible and how would I achieve it in general terms. I have tried various ways and can't quite get the timing correct. Hopefully this isn't too vague.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Set focus to new record (2003 SP3)

    You can do the following:
    - Set focus to form B (if that hasn't already happened).
    - Set focus to the subform on form B (idem).
    - Move to a new record.

    The code would look like this:

    Forms!FormB.SetFocus
    Forms!FormB!SubForm.SetFocus
    RunCommand acCmdRecordsGoToNew

    FormB is the name of form B, and SubForm is the name of the subform as a control on form B. This is not necessarily the same as the name of the subform in the database window. To find the control name, open form B in design view and click once on the subform. The title bar of the Properties window (and the Name property in the Other tab) will display the control name.
    If either of these names contains spaces or punctuation, enclose it in square brackets, e.g. [Form B]

  3. #3
    4 Star Lounger
    Join Date
    Dec 2002
    Location
    Kitchener, Ontario, Canada
    Posts
    421
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set focus to new record (2003 SP3)

    Thanks so much Hans. That worked, although the final code needs to be DoCmd.RunCommand does it not? or can you use RunCommand without the DoCmd?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Set focus to new record (2003 SP3)

    You can use RunCommand without DoCmd. It is a method of both the DoCmd and Application objects, so you can use DoCmd.RunCommand, Application.RunCommand, and since you can usually omit Application, also RunCommand by itself.

Posting Permissions

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