Solved

Ms Access SQL not updating when form is open

Posted on 2014-01-02
2
445 Views
Last Modified: 2014-01-03
I have form that prints an Invoice. When the invoice is printed it updates the inventory table to adjust for the number of items sold. I do this with the following statement.

    DoCmd.RunSQL "UPDATE tblInvoiceDetail INNER JOIN tblInventoryData ON " _
    & "tblInvoiceDetail.Partno = tblInventoryData.Partno SET " _
    & " tblInventoryData.QuanInStock = [tblInventoryData].[QuanInStock]-[tblInvoiceDetail].[OrderQuan] " _
    & "WHERE (((tblInvoiceDetail.[InvNo])=" & InvNo & ") AND ((tblInventoryData.DropShip)<>-1));"
   
This works perfectly but if my Inventory form is also open to one fo the items being updated, the update for that item does not occur. What can I do to fix this?
0
Comment
Question by:EclecticBob
2 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39752870
Access may have that record locked.

You could close the form if it's open, if that would work. To do that, run this just before  you run your query:

On Error Resume Next
DoCmd.Close acForm, "YourFormName"

Or you may just need to save any pending changes. You can do that in several ways. My favorite is to include a routine on the form to run standard record save code. In the form's code module, do something like this:

Function SaveForm() As Boolean
  If Me.Dirty Then Me.Dirty = False
End Function

To use that:

Forms("YourFormName").SaveForm

and then run your query.
0
 

Author Closing Comment

by:EclecticBob
ID: 39754432
Thank you, I'd rather not have to close the form but the SaveForm routine looks like the solution.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

806 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