Set focus to sub form from main form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gerhard Heemskerk
    New Member
    • Feb 2007
    • 6

    Set focus to sub form from main form

    Hello,

    I have a button on the main form and the follwing code when you click on it. Though the last record is the sub form (datasheet view) is shown, the focus remains on the button last_transactio n on the main form. I tried to get the focus on the sub form
    Code:
     form_transaction.setfocus
    but i get an error 'the expression contains an invalid methode'. When I search for a solution everyone states that the above statement should work. But the focus remains on the button on the main form. What's wrong?
    Thanks in advance
    kind regards,
    gerhard

    Code:
    Private Sub last_Transaction_Click()
    
    'On Error GoTo Err_last_Transaction_Click
    
    Dim frm As Form
    
    Form_transaction.OrderBy = "transaction_number,transaction_date"
    Form_transaction.OrderByOn = True
    
    'Set reference to "subform"
    Set frm = Form_transaction.Form
    
    'Goto last record in subform
    If frm.RecordsetClone.RecordCount > 0 Then
     frm.SelTop = frm.RecordsetClone.RecordCount
    End If
    
    Exit_last_Transaction_Click:
           Exit Sub
    
    Err_last_Transaction_Click:
        MsgBox Err.Description
        Resume Exit_last_Transaction_Click
    
    End Sub
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    The subform object does not necessarily have the same name as the form used as the subform. Open the main form in design view and click on (not in) the subform object. Open the properties window and under the other tab check the value in the Name property. This is the name of the subform object.

    You are not refering to a form but to a subform object.

    To refer to the main form use Me.

    To refer to a control on the main form
    Me.ControlName

    To refer to a property of the main form
    Me.PropertyName

    To refer to a control on the subform
    Me.SubformObjec tName.Form.Cont rolName

    To refer to a property of the subform
    Me.SubformObjec tName.Form.Prop ertyName

    Mary

    Comment

    • Gerhard Heemskerk
      New Member
      • Feb 2007
      • 6

      #3
      Originally posted by mmccarthy
      The subform object does not necessarily have the same name as the form used as the subform. Open the main form in design view and click on (not in) the subform object. Open the properties window and under the other tab check the value in the Name property. This is the name of the subform object.

      You are not refering to a form but to a subform object.

      To refer to the main form use Me.

      To refer to a control on the main form
      Me.ControlName

      To refer to a property of the main form
      Me.PropertyName

      To refer to a control on the subform
      Me.SubformObjec tName.Form.Cont rolName

      To refer to a property of the subform
      Me.SubformObjec tName.Form.Prop ertyName

      Mary
      Hello Mary,

      It seems like the field client, within sub form transaction (dataview) got focus after clicking on the button last transaction in de main form. But that;s not the case. It is colored black. But still the button in the main form has the focus. Only clicking on client gives the focus on the sub form 'transaction'. The main form is called transaction.ent ry and the sub form transaction. The statement form_transactio n.setfocus or form_transactio n.klant stated in the sub of the button 'last transaction' still creates an error message. Please do you have a solution..
      kind regards
      gerhard

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        Try:

        form_transactio n.form.client.s etfocus

        Nic;o)

        Comment

        • Gerhard Heemskerk
          New Member
          • Feb 2007
          • 6

          #5
          Originally posted by nico5038
          Try:

          form_transactio n.form.client.s etfocus

          Nic;o)
          Hello Nico,
          Thanks for your answer but I got then following error:
          By the application of object not defined error ..

          kind regards
          gerhard

          Comment

          • nico5038
            Recognized Expert Specialist
            • Nov 2006
            • 3080

            #6
            Make sure that the formname and controlname are correct!

            Nic;o)

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32668

              #7
              Try setting the focus on the main form to its subform object first. Only then, set the focus to the item on the subform.
              For help referencing the various controls and forms see (Referring to Items on a Sub-Form).

              Comment

              Working...