Refresh form data

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Refresh form data

Post by burrina »

I have a main form that stays open all the time. Sometimes I change the data on other forms that are reflected on this main form and need it to display the latest data when it has the focus again.
What event should I use and code to do this?

RESOLVED:
Thanks,
Last edited by burrina on 29 Jan 2017, 21:51, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refresh form data

Post by HansV »

You could use the On Got Focus event of the form. If you have merely modified existing records, you can use the Refresh method; if you may have added or removed records, use the Requery method. For example:

Code: Select all

Private Sub Form_GotFocus()
    Me.Refresh
End Sub
Remark: because the Requery method loads the record source of the form again from scratch, the form will jump to the first record by default.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Refresh form data

Post by burrina »

The form is unbound, only some data on it uses either an expression or DLookup.

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refresh form data

Post by HansV »

In that case, you can use Me.Recalc instead of Me.Refresh.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Refresh form data

Post by burrina »

Thanks