Solved

I cannot get the results of an update query to appear on my Access form

Posted on 2014-11-11
4
154 Views
Last Modified: 2014-11-11
I have a form that is actually a main form, a tabbed form, a subform on a tab, and a subform within that tab.  The subform pulls from its own table and is populated by selecting one option from a provided dropdown box.  I attached a macro to choose whether a new record needs to be added using the dropdown selection or whether an existing one needs to be updated.  

Once the update has been made to the record, I'm trying to reflect the change on the form.  I keep getting a conflict message.  I've attached a copy of the subform and the error message.  help.

  the subformthe error
0
Comment
Question by:jwandmrsquared
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40436256
You are conflicting with yourself.  The form is bound and something made it "dirty" so Access knows the current record needs to be saved.  You then ran a macro to update the bound record.

It is never a good idea to use an update query to update the record you are looking at.

You can start by figuring out what is dirtying the current record.  Is your combo bound?  If so, that would do it.  You should not be using a bound combo to enter selection criteria.  If you can keep the current record from becoming dirty before you run the update, you may be able to prevent the scary message or it may just move to the point in time where you try to save the current record using the form.

I don't have a clear picture of what you are trying to do so I can't be too specific. Usually an "add new" button just moves the current record to a "new" record.  It sounds like you are having the user enter some value BEFORE you move to the "new" record and that could be the issue.
0
 

Author Comment

by:jwandmrsquared
ID: 40436317
I ended up converting the macro to vba, then inserting a requery statement. I've tested numerous times and it seems to be working.  I am keeping your notes above about not updating the record you are on, I didn't know that.
0
 

Author Closing Comment

by:jwandmrsquared
ID: 40436318
Guided me in the right direction.
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40436357
The requery is forcing the current record to be saved and so since it is no longer dirty, the message went away.  This gets you past the error message but I suggest that you rethink the entire process in light of my earlier comments.  

I'm going to add another "never".  Never rely on the byproduct of a statement.  If you want to save the record, save it using the correct VBA command - DoCmd.RunCommand acCmdSaveRecord OR in some cases you might need to use
If Me.Dirty Then
    Me.Dirty = False           '''force save record
End If

If you ever have to use the Me.Dirty trick (and it is a trick since it obfuscates the actual action), always comment it because the obvious interpretation of the statement is that you are cancelling the update by resetting the dirty flag rather than forcing the update.

Both requery and refresh as a side effect, save the current record but they have awkward side effects that you don't get if you simply save the current record.  I'm telling you this because you didn't know that the Requery was forcing the record to be saved and that was why the message went away and someday, you might run into trouble because you used Requery rather than the correct save instruction.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now