Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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

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
jwandmrsquared
Asked:
jwandmrsquared
  • 2
  • 2
1 Solution
 
PatHartmanCommented:
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
 
jwandmrsquaredAuthor Commented:
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
 
jwandmrsquaredAuthor Commented:
Guided me in the right direction.
0
 
PatHartmanCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now