none
Method Focus does not work in Datasheet view RRS feed

  • Question

  • To work dynamically, I set the RecordSource of forms in the Open event. In the Load event, I control which field gets the focus. Below is a simple representation of the code.

    CtlName and SQLStatement are a Constant and a Function (both type String). And of course, how you pass on the value does not matter. That is not the fault.

    When the technique below is applied to a form in the datasheet view, it does not work: the field (CtlName) does not get the focus, but it works in every other view. I therefore assume that this is a bug, because this is quite remarkable.

    Note: if the method SetFocus is executed in the Open event after the RecordSource has been set, it will work in Datasheet view. But for several reasons, I prefer to do this in the event Load.

    I use the Dutch version of Access, version:

    Private Sub Form_Load ()
         On Error Resume Next
         Me (CtlName) .SetFocus
         On Error GoTo 0
    End Sub

    Private Sub Form_Open (Cancel As Integer)
         Me.RecordSource = SQLStatement
    End Sub


    Sunday, July 22, 2018 1:32 PM

All replies

  • To work dynamically, I set the RecordSource of forms in the Open event. In the Load event, I control which field gets the focus. Below is a simple representation of the code.

    ...

    When the technique below is applied to a form in the datasheet view, it does not work: the field (CtlName) does not get the focus, but it works in every other view. I therefore assume that this is a bug, because this is quite remarkable.

    Hi Peter,

    First of all, I am interested in your dynamically way of working. What is the variability in the RecordSource? The fields to display, the WHERE clause and the SORTED BY clause?

    In all my applications I only use RecordSources that are defined in the Open event of the form. As far as I can remember from some experiments a long time ago, just changing/setting the RecordSource ALSO triggers the Load (?) and the Activate event. Perhaps there is some conflict between the setting of the RecordSOurce and the Load event especially for Datasheet view. I have no experience with the Datasheet view, I never use it. Instead I use a generalized "normal" form and a definition table to display "any" recordset.

    Imb.

    Sunday, July 22, 2018 7:16 PM
  • It does not matter which fields, criteria, order etc. are set, as long as the SQL-statement is correct. I can submit the problem again, but that only makes it confusing.
    Sunday, July 22, 2018 7:40 PM