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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh problem 2

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
I have two forms and will call them formA and formB. formA has a button that, when clicked, closes formA and opens formB:

DoCmd.Close acForm, "formA"
DoCmd.OpenForm "formB"

formB is to enter data for a new primary field. When formB is done and the user clicks a "Create" button a table is opened and the data is entered into it. Then the table is closed, formB is closed and formA is opened.

DoCmd.OpenForm "formA"
DoCmd.Close acForm, "formB"

Now the problem: formA does not display the data just added to the table. However, when doing a record count the recordcount value is incremented by one so it sees it but does not display it. It displays empty fields for the last record.

If I close formA and re-open it the record data appears.

Any ideas what is causing the record count to be accurate but not displaying the record data?

Thank you.


 
I just tried that and that docmd.requery is limited to form objects. Trying to do a docmd.requery "tableName" or docmd.requery "formName" does not work.

Nice try, though.

Any other ideas?

Thank you.
 
If your recordset count is increasing then the table is definitely updating and it is your form that is the problem. Is the form bound directly to a linked table or is it assigned to a recordset at run-time? If its bound to a recordset you could just recreate the recordset and assign it to the form's recordsource thus forcing a requery. I usually just play around with the Requery command until it works. I have experienced a lot of frustration with this in the past. If all else fails you could always try programmatically closing and reopening the form. This looks unattractive but works. hope this helps
 
Orion45; Your last post describes the problem I am having. I agree that this is frustrating and time-consuming.

I think it is bound to a linked table because the properties of form.data.recordsource show the table that is giving me the problem.

Can you recommend ideas on what you do when you play around with the Requery command?

Thank you.
 
Sometimes specifying the exact form you want to requery works.
[Forms]![YourFormNameHere].Requery

Sometimes using a Refresh statement after a requery works.
Me.Requery
Me.Refresh

Sometimes setting the focus to the form first works.
[Forms]![YourFormNameHere].SetFocus
docmd.requery

And when nothing works I might just close the form and reopen it (if open causes the screen to blink).
DoCmd.Close acForm, "YourFormName"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Working with forms bound to linked tables can be temperamental, I've switched to using ADO Recordsets and have had a lot more success.
 
Orion45; Here is a Star and a 'Thank You' for your tips and time [thumbsup2]
 
Hello.
You wrote:

DoCmd.OpenForm "formA"
DoCmd.Close acForm, "formB"

From this we can conclude:
FormA is opened while formB is still opened, BUT NOT UPDATED!
You have to use:

docmd.runcommand acCmdSaveRecord on formB and then write:

DoCmd.OpenForm "formA"
DoCmd.Close acForm, "formB"

BECAUSE, RECORD HASN'T BEEN UPDATED AT THAT MOMENT ON FORM B. WITH THIS ACCMDSAVERECORD COMMAND, YOU'LL DO IT BEFORE YOU OPEN FORM A AND THE RECORD WILL BE DISPLAYED ON FORM A!



 
alfalf; This is an easy fix to a messy and time-consuming problem. Thank you for sharing this!

Ya just got a star [thumbsup]

MrMajik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top