How do refresh a form?

J

Jamie Loren

I have Form1 that is the base for my app. A button on Form1
causes Form2 to pop up. After the user is done with Form2 then
he/she click the OK button on Form2. How can I cause Form1
to be refreshed after the user clicks OK on Form2?
 
B

Baz

Jamie Loren said:
I have Form1 that is the base for my app. A button on Form1
causes Form2 to pop up. After the user is done with Form2 then
he/she click the OK button on Form2. How can I cause Form1
to be refreshed after the user clicks OK on Form2?

DoCmd.OpenForm "Form2", WindowMode:=acDialog
Me.Requery
 
G

Guest

You can either make form 1 close when form2 pops up and then open again when
form 2 closes,
or
use form.refresh in the form_gotfocus() section of code in form 1.

I prefer to use the second one as it allows form1 to remain open.

HTH
Rhys
 
J

Jamie Loren

DoCmd.OpenForm "Form2", WindowMode:=acDialog
Me.Requery

It was a nice try, but it didn't work. I need Form1 to be
requeried after the user clicks OK on Form2 because
Form2 puts an entry into a table that Form1 needs to see.

Any other ideas?
 
D

Douglas J Steele

Jamie Loren said:
It was a nice try, but it didn't work. I need Form1 to be
requeried after the user clicks OK on Form2 because
Form2 puts an entry into a table that Form1 needs to see.

That's exactly what that does, Jamie.

The code goes into Form1.

The first line (the DoCmd.OpenForm) opens Form2 in dialog mode, which means
that you can't do anything else until that form has been closed.

The second line requeries the recordsource for the form.
 
J

Jamie Loren

You can either make form 1 close when form2 pops up and then open again
when
form 2 closes,
or
use form.refresh in the form_gotfocus() section of code in form 1.

I prefer to use the second one as it allows form1 to remain open.

I really thought that was going to work, but for some reason
it just seems to ignore the form.refresh in the form_gotfocus()
section of Form1. Am I missing something? I also tried putting
msgbox "hello" in the gotfocus() section but it doesn't do that
either. It's acting like it is ignoring this section. Any idea what
I am missing?
 
G

Guest

Ignore my advice. I just tested my app and the form.refresh doesn't work. I
thought it did but I still had some old code that did the job in there.

Does it work if you simply reopen the form1 when the button on form 2 is
clicked?
 
B

Baz

Jamie Loren said:
It was a nice try, but it didn't work. I need Form1 to be
requeried after the user clicks OK on Form2 because
Form2 puts an entry into a table that Form1 needs to see.

Any other ideas?

I assumed from the presence of the OK button on Form2 that it was a dialog
box that would close when OK was pressed. This would be the normal
purpose/behaviour of an OK button. However, if Form2 continues to sit there
after the OK button is clicked (a strange design!) then the quick-and-dirty
way to do it is to put this in the Click event for the OK button:

Forms!Form1.Requery
 
J

Jamie Loren

That's exactly what that does, Jamie.
The code goes into Form1.

The first line (the DoCmd.OpenForm) opens Form2 in dialog mode, which
means
that you can't do anything else until that form has been closed.

The second line requeries the recordsource for the form.

My apologies. I had mistyped the code. Your explanation really
helped alot. Thank you so much. It worked.
 
J

Jamie Loren

Awesome thank you.



Baz said:
I assumed from the presence of the OK button on Form2 that it was a dialog
box that would close when OK was pressed. This would be the normal
purpose/behaviour of an OK button. However, if Form2 continues to sit
there
after the OK button is clicked (a strange design!) then the
quick-and-dirty
way to do it is to put this in the Click event for the OK button:

Forms!Form1.Requery
 
B

Baz

Jamie Loren said:
I really thought that was going to work, but for some reason
it just seems to ignore the form.refresh in the form_gotfocus()
section of Form1. Am I missing something? I also tried putting
msgbox "hello" in the gotfocus() section but it doesn't do that
either. It's acting like it is ignoring this section. Any idea what
I am missing?

That method makes no sense. If the OK button on Form2 closes Form2, then
the first method I gave you will work if you have implemented it correctly.
If the OK button doesn't close Form2, then merely clicking the OK button
will not cause the GotFocus event to fire on Form1. Use the second method I
gave you.

Also, the Refresh method is not terribly useful. The Requery method is
almost certainly what you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top