Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316

    Unanswered: Keeping Focus after Requery method

    When I use the Requery method within a form, how can I keep the focus on the control which had the focus just prior to the requery? The solution needs to work with sub-forms too (i.e. requery a main form from within a subform and keep focus within the subform). Any help much appreciated.
    Last edited by bcass; 01-10-03 at 18:09.

  2. #2
    Join Date
    Oct 2002
    Location
    NSW Australia
    Posts
    61
    just use the setfocus property:

    me.somecontrol.requery
    me.mycontrol.setfocus

    :0)

  3. #3
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    I forgot to mention that my subform is a continuous form, so your method wouldn't work. For example, if field 2 of record 2 on row 2 had the focus, and I did a requery of the main form, how do I return focus back to field 2 of record 2 on row 2? Is there someway I can assign the control that has the focus to a variable, do the requery, then refer to the variable to setfocus?

  4. #4
    Join Date
    Oct 2002
    Location
    NSW Australia
    Posts
    61
    the me.currentrecord will give you the row of the "current record" which has the focus.
    I'm sure you could play with that. EG.

    DoCmd.GoToRecord acDataForm, "Employees", acGoTo, 7
    Takes you to the 7th record on that form.

    so you could try setting a variable to me.currentrecord before your requery and then use that variable in the above statement.

    HTH

    :0)

  5. #5
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    very small notes:

    try to avoid REQUERY, I'm not sure what you are trying to do, but REFRESH, REPAINT and MOVE to next record and back can do (maybe) your job.

    REQUERY really re-reads whole recordset and although you can use GoToRecord, if you have multi-user database, you don't need to hit the same record and it's better (sometimes) to remember UniqueID, then REQUERY and then SEEK for that UniqueID..... but if you have few users, it's much easier to use denofdeath's method, it will work.

    :-)

    jiri

  6. #6
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    OK, I tried this:

    Forms!frmDataEntry!fsubRequestDetails1.SetFocus
    varCurrentRecordPointer = Me.CurrentRecord
    DoCmd.GoToRecord acDataForm, "fsubRequestDetails1", _
    acGoTo, varCurrentRecordPointer


    But it gives me the following error:

    Run-time error '2489':

    The object 'fsubRequestDetails1' isn't open.


    fsubRequestDetails1 is open when I execute the code, so what could be wrong? I also tried:

    DoCmd.GoToRecord acDataForm, "Forms!" & _
    "frmDataEntry!fsubRequestDetails1", _
    acGoTo, varCurrentRecordPointer


    But it gives the same error.
    Last edited by bcass; 01-15-03 at 15:32.

  7. #7
    Join Date
    Oct 2002
    Location
    NSW Australia
    Posts
    61
    Try running the requery from the control in the subform so it never loses focus. ie

    from a onclick event in a button in the detail put:

    me.parent.refresh

    or

    me.parent.somefield.requery

    etc...

    HTH

Posting Permissions

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