How to set focus to a field on subform which is placed on a tab of the mainform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pierkes
    New Member
    • Feb 2013
    • 64

    How to set focus to a field on subform which is placed on a tab of the mainform

    Hi,

    I have a

    - mainform called: [frm_traject_det ails]
    - a page on the mainform called: [page_status - resultaat]
    - a subformelement (for displaying subform) called: [Redenen van winst of verlies]
    - a subform called frm_reden

    - a combobox on the subform called: cmb_reden_cat

    When a certain criteria is not met, i want to show a message and set the focus to a field on the subform.

    On the page i have a field in which, in the BeforeUpdate procedure, i have;

    Code:
    Private Sub Form_beforeupdate(Cancel As Integer)
    DoCmd.Echo True
    Dim ctl As Control
    
    If Me![Status Res] <> 5 And Me![Soort traject] < 6 And Me![chk_reden] = False Then
    MsgBox ("Het resultaat van dit traject is " & [Status Res].Column(1) & ", geef aan wat de reden(en) hiervoor zijn aub!")
    Me.[Redenen van winst of verlies].SetFocus
    Me.[frm_redenen].SetFocus
    Me.[Redenen van winst of verlies]!cmb_reden_cat.SetFocus
    Cancel = True
    Exit Sub
    
    End If
    It will generate an error message stating it cannot set focus to [Redenen van winst of verlies]

    Any suggestions ?

    Thanks,
    Pierkes
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Pierkes,
    Here is a page a lot of us refer to for help with form/subform references


    Jim

    Comment

    • jforbes
      Recognized Expert Top Contributor
      • Aug 2014
      • 1107

      #3
      If you are calling the Form_beforeupda te from the main form, I think you want to replace lines 7-9 with:
      Code:
      Me![Redenen van winst of verlies].Form![cmb_reden_cat].SetFocus
      So you would end up with:
      Code:
      Private Sub Form_beforeupdate(Cancel As Integer)
       DoCmd.Echo True
       Dim ctl As Control
       
       If Me![Status Res] <> 5 And Me![Soort traject] < 6 And Me![chk_reden] = False Then
       MsgBox ("Het resultaat van dit traject is " & [Status Res].Column(1) & ", geef aan wat de reden(en) hiervoor zijn aub!")
       Me![Redenen van winst of verlies].Form![cmb_reden_cat].SetFocus
       Cancel = True
       Exit Sub
       
       End If
      Access's syntax can get a little ugly.

      Comment

      Working...