Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh automatically

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
After adding data to a form how can I automatically refresh the form after exiting the form? I currently have a refresh button to show the additions. I was wondering if ther e was a way to update the form after exiting the form?
 
I should make it clear that my form has an add form button that adds a record to the the main form. When I exit the add form the current form doesnt show the changes made until after I hit the refresh button or move to another record and then come back to the record.
 
Try putting:

Me.Refresh

in the after update event of whatever field you are adding data to. - it's the same as pushing the Refresh button.

If the data is not appearing in a different form than the one you are adding data to (I think that's what you are doing) perhaps put the same code in the "Got Focus" event of the main form.

Of course there are probably 15,000,000 ways to do this, but that's what I would try.

Monkey
 
I tried as suggested but my form still does not refresh after I add a record. I have to hit the refresh button still.
 
If I understand correctly, you have two different instances of the same form so Me.Refresh wouldn't work since it would refresh the wrong instance of the form. Try refreshing the form on the on close event of the add form but don't use Me.Refresh, try Form_YourFormsName.Refresh instead.

Cheers,

Pete
 
Bravo.

I was on the right street - just going the wrong direction.

 
I tried as suggested and got error message.

Private Sub Form_Close()
Work.Refresh
End Sub

The name of my form that needs to be refreshed is call "Work"

I put this Refresh part in the close event of the add form (The add form is called "AddWork")

Any other suggestions???
 
Your code should read

Private Sub Form_Close()
Form_Work.Refresh
End Sub

or

Private Sub Form_Close()
Forms![Work].Refresh
End Sub

One should work.

So do you have two forms which are identical except one is only used for adding data into the other form while the other is used to edit/view/delete this same data?

Why not just open the form in add mode when adding a form, and in normal mode for the rest? This would reduce the need to have two identical forms and depending on how you did it, would make the refreshing needless.

Sorry if I've got the wrong end of the stick.

Cheers,

Pete
 
So I understand what you are going through:

You have a form Work. On this form, you have a button (I'm guessing) that opens the "AddWork" form.

After completing the record update, you are closing the "AddWork" form and wanting to view the original form - with the added data.

Right?

I'm not sure of your level of expertise, so I'll assume you are a beginner, and take what you want from this explanation.

1) In your form "Work" put a button that has this in the on click:

Dim stForm As String

'Define form name
stForm = "AddWork"

'Open form in add mode
Docmd.OpenForm stform,,,,acFormAdd

2) In the open event of "AddWork" put this:

Dim stForm As String

'Define form name
stForm = "Work"

'Close open form
DoCmd.Close acForm,stForm,acSaveNo

3) In the close event of "AddWork" put this:

Dim stForm As String

'Define form name
stForm = "Work"

'Open form
DoCmd.OpenForm stForm

The above codes have no error handling built in - if you want that I'll have to send it later. All those codes do are open and close forms, thus the newly opened forms will have the "refreshed" data available.

Just a suggestion - I would make the "AddWork" form an unbound form and have a Query append the data from "AddWork" to your TblWork - I've found that doing it this way is much more efficient and it give you some more control over what information is going into your database.

Confused? I hope not.

Pete's idea will work fine too - as far as code goes. Try that first, it may be easier. However, I would consider using queries to append data as opposed to using the form in add mode. Depending on the level of expertise of your users doing so might save you some headaches later.

If you don't know how to set up a query to append from an unbound form let me know.

Sorry for my long windedness (is that a word?)

Hope I didn't do more harm than good.

Monkdy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top