none
Me.Requery - and then return to the row/control RRS feed

  • Question

  • Hi

    I have a form with data. The database is running in a network. One user may update data that others might have interest in.

    Some data is on a status form. My idea is to use TimerEvent to update the status form on a regular basis. And it works fine using Me.Requery.

    But if some user is pointing to a row or control on the status form, then Me.Requery moves focus from that specific control to the first row of the form.

    I am trying to have a code that allows Me.Requery and at same time, if some one is pointing/clicking on a control, the focus shall return to that specific control.

    'Here is my start

    Dim ctl As Control
    Set ctl = Forms!Produktion![Alla tankar underformulär]![Tank nr Lagertank]
    Me.Requery

    ' And now whats the next line in code??

    DoCmd.GoToRecord acDataForm, "Forms!Produktion![Alla tankar underformulär]", ??????


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Monday, September 5, 2016 10:45 AM

Answers

  • Hi,

    Dim lngStore As Long
    lngStore =  Forms!Produktion![Alla tankar underformulär]![Tank nr Lagertank]
    
    Me.Requery
    Forms!Produktion![Alla tankar underformulär].Form.Recordset.FindFirst "[Tank nr Lagertank]= " & lngStore
    
    I'm not sure where the code is i.e. if Me/Forms... are the best references but you should get the idea. If "Tank nr Lagertank" is not a long type field you have to change the variable type. In any case you should take the PK of the table or at least a guaranteed unique field that reliably identifies the record.


    cu
    Karl
    Access FAQ (de/it): donkarl.com
    Access Lobby: AccessDevelopers.org

    • Marked as answer by ForssPeterNova Monday, September 5, 2016 11:49 AM
    Monday, September 5, 2016 11:01 AM

All replies

  • Hi,

    Dim lngStore As Long
    lngStore =  Forms!Produktion![Alla tankar underformulär]![Tank nr Lagertank]
    
    Me.Requery
    Forms!Produktion![Alla tankar underformulär].Form.Recordset.FindFirst "[Tank nr Lagertank]= " & lngStore
    
    I'm not sure where the code is i.e. if Me/Forms... are the best references but you should get the idea. If "Tank nr Lagertank" is not a long type field you have to change the variable type. In any case you should take the PK of the table or at least a guaranteed unique field that reliably identifies the record.


    cu
    Karl
    Access FAQ (de/it): donkarl.com
    Access Lobby: AccessDevelopers.org

    • Marked as answer by ForssPeterNova Monday, September 5, 2016 11:49 AM
    Monday, September 5, 2016 11:01 AM
  • You may like to use a reusable procedure I created for this purpose a while ago, see: http://www.devhut.net/2012/10/19/ms-access-vba-requery-a-form-while-remaining-on-the-same-record/

    -- Daniel Pineault, 2010-2015 Microsoft MVP Professional Support: http://www.cardaconsultants.com MS Access Tips and Code Samples: http://www.devhut.net

    Monday, September 5, 2016 11:05 AM
  • Thanks Karl

    "Tank nr lagertank" is long type.

    So your code is perfect. It's running now.


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Monday, September 5, 2016 11:51 AM
  • Thanks Daniel

    Useful link. I'll remember it.

    In this case I used Karls code.


    Best // Peter Forss Stockholm and Sigtuna GMT +1.00

    Monday, September 5, 2016 11:52 AM