Go Premium for a chance to win a PS4. Enter to Win

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

Ms Access SQL not updating when form is open

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
EclecticBob
Asked:
EclecticBob
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
EclecticBobAuthor Commented:
Thank you, I'd rather not have to close the form but the SaveForm routine looks like the solution.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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