Form Refresh

EHS

Registered User.
Local time
Today, 03:15
Joined
Jun 23, 2011
Messages
22
Hello. I am trying to automatically refresh a form when focus returns to it. When I click on a control in the form another form is opened for new record entry. When the new record entry form is closed, the original form does not display the new data (the original form is tabular). I've tried me.refresh and me.requery in the gotfocus event without success. Any ideas?
Thanks
 
Have you tried stepping thru the code when it runs to make sure that the Me.Requery line is fired?
 
I assume you're talking of the GotFocus event of your original Form. The problem is that a Form cannot receive Focus if it contains any Controls that can receive Focus!

So use the Form's OnActivate event. In the original Form:
Code:
Private Sub Form_Activate()
 Me.Requery
End Sub
Linq ;0)>
 
Thanks all of you for your help. The code, of course, was not being executed. I placed a refresh macro in the 'on activate' event for the original form, and it worked a treat!
 
Hello again. I have changed the refresh to requery as per Missinglinq's suggestion. Thanks again all of you.
 
Ok, I used the method that was mentioned in this thread to refresh my form but it isn't working. The only difference that may be there is that I am using a Popup Form for my New Entries. Could this prevent the main form from executing the OnActivate?
 
Just a side note to my note above ... I added a Forms![FormName].Requery into the VBA for my New Entry form to execute just before the New Entry form is closed. This works just as well.
 
Have you placed the requery in the originating form?
 
Yep, I placed it on the originating form but it didn't work.

The only thing that I can think of is since I am using a Popup sub-form, it is opening in a new window, so the originating form is never losing focus or is not re-activating upon closing the sub-form window. Were you using a Popup sub-form for your new entries?

The nice thing is that the refresh I placed just before the sub-form closes after adding a new record is working just as it should. It may not be ideal, but it does the trick and it's the only place I need it.
 
Hi you all,

I came in here looking for advice on this issue, and I got it solved, thaks to some gidence I got here:

I have Form A, with loads of data, and Form B for data entry and updates. When Form B finishes the update, I have form A return to the same ID.

Form B is Pop-up, not modal, therefor can lose focus.

After runnig DoCmd.Refresh on Form B, I call Form A, Passing in the current ID:
Code on Form B:
Code:
    Me.Refresh
    Forms("FormA").ReQueryForm IIf(Me.ID> 0, Me.ID, -1)
Code on Form A:
Code:
Public Sub ReQueryForm(Optional ID As Long = -1)
    Me.Requery
    If ID > 0 Then
        Me.SetFocus ' I dont Know why, but it won't work with out this!
        Me.ID.SetFocus
        DoCmd.FindRecord ID
    End If
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom