Results 1 to 11 of 11

Thread: Forms (2002)

  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forms (2002)

    I have a form, that has a tab control with five tabs. On tab one I have a subform used for data entry, on tab two I have a form that displays information about the item entered on tab one. Tab two contains a subform, that contains another subform. After the items is keyed in tab one, I'd like focus to be set to the new record added in tab one. I'm not sure if there's something about form design I don't understand or if I just haven't found the right VBA syntax to manipulate the form focus. I pasted some of the code I've tried below. My suspicion is that I'm not referencing the subform control and/or the actual form correctly on page one of the tab control. Any help would be appreciated.


    ' DoCmd.GoToPage 1
    ' DoCmd.GoToRecord acDataForm, "frmMtchd", acNewRec
    DoCmd.GoToControl Forms!sfrMtchd!frmMtchdSlctn.Hs_Nmbr
    DoCmd.GoToRecord acDataForm, Screen.ActiveForm.Name, _
    acNewRec

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

    Re: Forms (2002)

    You can set focus to a subform using SetFocus; you must refer to the name the subform has as a control on its parent. This is not necessarily the same as the name of the subform in the database window. To see the control name, open the parent form in design view and click ONCE on the subform. Not twice, for then you will select something in the subform; if you do that by accident, just click on the parent form outside the subform, then try again. The name of the subform as a control will be listed in the Other tab of the properties window (and in the Object dropdown on the Formatting toolbar.)

    You can use RunCommand acCmdRecordsGoToNew to move to a new record in the form that has the focus without specifying its name.

    Me.[SubformAsControl].SetFocus
    RunCommand acCmdRecordsGoToNew

  3. #3
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms (2002)

    The subform control name is frmMtchdSlctn, the source form is as well. I get a "Method or data member not found" error when I compile. The subform control name is not in the drop down list when I type Me. I'm trying to set focus during an on-click event from tab 0's data entry form.

    Me.frmMtchdSlctn.SetFocus
    RunCommand acCmdRecordsGoToNew

  4. #4
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms (2002)

    Any good references or samples on how to manipulate forms, controls, and record selection would be appreciated. I checked the MS Knowledge base, but couldn't turn anything up.

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

    Re: Forms (2002)

    If frmMtchdSlctn is not in the IntelliSense list when you type Me., that is not the name of the subform control. Simple as that. Is it perhaps the name of the sub-subform?

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

    Re: Forms (2002)

    The Access Web on the MVPS site contains a number of very useful tips. One of them is Forms: Refer to Form and Subform properties and controls.

  7. #7
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms (2002)

    frmMtchdSlctn is a subform, on a form as a page on page 1 in a tab control. I'm trying to set focus to the subform from an onclick event from a command button on a form that is located on page 0 of the tab control. Thanks for the reference to the Access Web, that specific example was exactly what I'm looking for. Unfortunately, I still am not getting it done. I've tried the code below, and some other forms, but I still get an error that says Access can't find frmMtchd or some other error. Is Intellisense supposed to work with the ! syntax?

    Forms!frmMtchd!frmMtchdSlctn.SetFocus
    Me!frmMtchd.Form!frmMtchdSlctn.SetFocus

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

    Re: Forms (2002)

    I misunderstood your description higher up in this thread, I think I get it now. Intellisense only displays a complete list, including controls, for the (sub)form you're writing the code for. If you're going "up" to the parent, or "down" to a subform, you'll only get the built-in properties and methods. Try this:

    Me.Parent.SetFocus
    Me.Parent!frmMtchdSlctn.SetFocus

    This sets focus to the parent form first, then to the subform frmMtchdSlctn.

  9. #9
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms (2002)

    I'm not getting it, still get the error. I attached a sample, it's line 127 in the cmdAdd_Click event of frmPrprtyEntry.

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

    Re: Forms (2002)

    Thanks for attaching a copy of the database. Although I cannot test the following completely, since you didn't include tables and queries, at least I can now see what you have been talking about. You want to set focus to a subform of a subform (your use of "form" to describe the subform in the second tab put me on the wrong track). Try this code to set focus to the sub-subform:

    Me.Parent!sfrMtchd.SetFocus
    Me.Parent!sfrMtchd!frmMtchdSlctn.SetFocus

    Note: you haven't declared strCity and strZipCode in cmdAdd_Click.

  11. #11
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms (2002)

    Hans,

    Works perfectly. It's incredible how quickly and accurately you (and the other moderators) help people here. I just can't tell you how much I appreciate all the help.

    Thanks again.

Posting Permissions

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