Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    set focus to subform control (2000 all updates)

    Main form is called frmCustomers. Subform is called fsubProjects. Nested subform is called fsubMaterials.

    When on the fsubProjects subform, there is code behind the BeforeUpdate event
    <code>If Me.TotalMaterialsCost = 0 Then
    Select Case MsgBox("No Materials have been entered." _
    & vbCrLf & " Is this a ""Labour Only"" project?" _
    , vbYesNo Or vbExclamation Or vbDefaultButton1, "Labour only check")
    Case vbYes
    Call MsgBox("Thank you. Please continue.", vbExclamation Or vbDefaultButton1, "Project continue")

    Case vbNo
    Call MsgBox("Thank you. Please enter Materials.", vbExclamation Or vbDefaultButton1, "Enter Materials")
    Me.fsubMaterials.SetFocus
    Cancel = True
    Exit Sub
    End Select
    End If</code>

    Why does the line Me.fsubMaterials.SetFocus not work? It results in an error, stating that Access cannot find fsubMaterials.

    I have tried various formulations, including plugging in the entire main form name etc., but to no avail.

    What I want to do is get to the subform and then go to a control called "Category" and I realize that I must do this in 2 steps...but I have to get to the subform first, and that's a no go.

    Interestingly enough, if I put this code behind a Save command button, it works!

    Tom

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

    Re: set focus to subform control (2000 all updates)

    I don't think you can switch focus to a subform (or to another form, for that matter) in the Before Update event of a form. It would cause a conflict, since the record is in an unsaved state at that moment. The Cancel = True and the message box will have to do.

  3. #3
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set focus to subform control (2000 all updates

    Hans
    Thanks for your reply.

    No durn wonder I couldn't make it work! I struggled with it for almost 2 hours, trying to make sense of why I couldn't set the focus.

    Another lesson learned.

    Thanks again.

    Tom

Posting Permissions

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