How to refresh an access form
Asked Answered
M

6

7

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?

Mesentery answered 17/10, 2008 at 13:55 Comment(0)
D
7

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
Drumfire answered 17/10, 2008 at 14:51 Comment(0)
D
11

You can repaint and / or requery:

On the close event of form B:

Forms!FormA.Requery

Is this what you mean?

Drumfire answered 17/10, 2008 at 14:10 Comment(1)
No, it is like I want to run Form_Load of Form A,if it is possibleMesentery
D
7

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
Drumfire answered 17/10, 2008 at 14:51 Comment(0)
G
1

"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.

Grindle answered 17/10, 2008 at 14:55 Comment(3)
See Varun Mahajan's comment. Requery does not run the load events.Drumfire
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.Grindle
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.Grindle
R
1

I recommend that you use REQUERY the specific combo box whose data you have changed AND that you do it after the Cmd.Close statement. that way, if you were inputing data, that data is also requeried.

DoCmd.Close
Forms![Form_Name]![Combo_Box_Name].Requery

you might also want to point to the recently changed value

Dim id As Integer
id = Me.[Index_Field]
DoCmd.Close
Forms![Form_Name]![Combo_Box_Name].Requery
Forms![Form_Name]![Combo_Box_Name] = id

this example supposes that you opened a form to input data into a secondary table.

let us say you save School_Index and School_Name in a School table and refer to it in a Student table (which contains only the School_Index field). while you are editing a student, you need to associate him with a school that is not in your School table, etc etc

Rugg answered 22/3, 2013 at 13:3 Comment(0)
T
0

It probably wasn't necessary to do it all, but it was fast enough...

Forms![high volume binlocation editor].Requery
Forms![high volume binlocation editor].Refresh
Forms![high volume binlocation editor].Repaint
Turban answered 19/9, 2024 at 12:50 Comment(0)
M
-2

to refresh the form you need to type - me.refresh in the button event on click

Marismarisa answered 6/9, 2016 at 13:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.