views:

4420

answers:

3

I am building an MS Access application in which all the forms are modal. However, after data change in a form, I want to refresh the parent form of this form with newer data. Is there any way to do it. To elaborate further :

Consider there are two forms, Form A and Form B. Both are modal form. From Form A, I initiate Form B, and now Form B has the user attention. But at the close of form B, I want to refresh the Form A. Is there a way to do it?

+1  A: 

You can repaint and / or requery:

On the close event of form B:

Forms!FormA.Requery

Is this what you mean?

Remou
No, it is like I want to run Form_Load of Form A,if it is possible
Varun Mahajan
+1  A: 

No, it is like I want to run Form_Load of Form A,if it is possible

-- Varun Mahajan

The usual way to do this is to put the relevant code in a procedure that can be called by both forms. It is best put the code in a standard module, but you could have it on Form a:

Form B:

Sub RunFormALoad()
   Forms!FormA.ToDoOnLoad
End Sub

Form A:

Public Sub Form_Load()
    ToDoOnLoad
End Sub    

Sub ToDoOnLoad()
    txtText = "Hi"
End Sub
Remou
I didn't think of this earlier. Thank you very much
Varun Mahajan
+1  A: 

"Requery" is indeed what you what you want to run, but you could do that in Form A's "On Got Focus" event. If you have code in your Form_Load, perhaps you can move it to Form_Got_Focus.

CodeSlave
See Varun Mahajan's comment. Requery does not run the load events.
Remou
Which is why I suggested moving the code there to Form_Got_Focus (much like you did in your second answer). If he's wanting to refresh the data linked to the form, requery is the way to go.
CodeSlave
If hew wants to re-do the Load event, move the code to another sub (just as Remou demonstrated) and then called it in the load and then in his refresh routing (either when closing B or when re-entring A with a Got_Focus). Got Focus will also work if A opens other windows too.
CodeSlave