Solved

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

Posted on 2014-11-11
4
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 37

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 37

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

740 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