Discussion Locked

MS Access - Updating Form Record Source

0 helpful
13 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a form which displays the results of a query which is not updatable. I have created code to update the underlying values in the table. The problem is that I can not figure out a way to get the query to recalculate and display the new values on the form.

Anyone have any suggestions?

13 replies

by peyison

Bryan,

Try calling the refresh method of the form or of the control you want to update.

by susu

My first thoughts too. Unfortunately, contrary to what the help files say, this does not update the value in the control. The only way I seem to be able to get the new value to load is to unload the form and then load it again.

by peyison

Sorry about that - it's the Requery method of the control that you need.

If you have a list box tied to a table, and you update the table, calling the Requery method of the listbox will update it with the new data from the table.

by susu

It's not a list box or similar control that I am trying to refresh. The data source for the form is a query which is not updatable (i.e. I can not change the values in the fields directly). I change the values in one of the underlying tables programatically, but I need to re-run the query on which the form is based, in order to get the records to contain the correct data.

by bob sellman

me.recalc or me.requery (Access sometimes likes recalc and sometimes likes requery) should do the job.

The question is: what causes the updating code to execute? If, as I suspect, it is being run from another form, then you need to do something like this:

Let's assume that you display the "results" form and the user clicks a button to bring up your updating form. The user does the updates and clicks a button to save and close the form (or closes with another button after clicking save).

For the On Got Focus property of the results form, put the code:
me.requery (or me.recalc)

This means that whenever you do something with another form and return to the results form, the results form will recalculate the query and display thenew results.

by susu

Still no dice. . . The form is based on a crostab query. I have a button on the form which displays an input box and then uses the entry in that input box to update a field in the table. I have tried refresh, requery and recalc on both the form and the textbox control. nothing works.

BTW: This is Access 97.

by sankulpune

Hello Bryan,

I could not test the following solution but I hope it works.

After modifying the value in the table, use DoCmd.Requery method instead of Requery on the query; AND THEN Refresh the form.

Your feedback will be highly appreciated.

with regards,

SanganakSakha,
Simple And Effective Solutions To Small Problems, No QuickFixes.

by susu

Nope. I just tried it and that doesn't work either. The Requery method seems to be only for controls that use a query as their control source such as a list box, combo box or subform. I just need to requery/refresh/re-whatever the data for the wholeform. There must be a way to do this. If I am working in a multi-user database and someone changes some data from another PC, how do I go about making sure that the latest data is being shown in the form on my screen?

by meares

I too built a form that I was calculating values from a subform and displaying them on the main form. My sollution was; that after entering the last field (rather new or changes) on the subform I return the focus to the main form and called a publicevent that looped through the sub form records and recalcalted the fields need for display on the main form.

I also use the "On Focus" event to do a Me.Refresh that also refreshes the form from any changes made.

This discussion is closed to new replies.