Results 1 to 10 of 10
  1. #1
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    how to keep or alter message displayed when code is run

    Hi I have the following code that runs when my Inventory transactions form is opened. The code's purpose is when the user opens it from a button on my Order details form is to automatically subtract the quantity ordered from inventory. It works, but gives a message saying the open form action was cancelled and gives no clue that it was successful. Is there a way to stop this message and replace it with confirmation that the action was successful?

    Private Sub Form_Load()
    Dim lngProduct As Long
    Dim intPos As Integer
    Dim lngProductQty As Long
    If Not IsNull(Me.OpenArgs) Then
    ' Position of pipe
    intPos = InStr(Me.OpenArgs, "|")

    If intPos > 0 Then
    ' Retrieve Product from 1st part of string
    lngProduct = Left$(Me.OpenArgs, intPos - 1)
    ' Retrieve ProductQty from the end of string


    lngProductQty = Mid$(Me.OpenArgs, intPos + 1)
    DoCmd.GoToRecord , , acNewRec
    'Assign 1st value to control
    Me.Product.SetFocus
    Me.Product = lngProduct
    Me.TransactionType.SetFocus
    Me.TransactionType = "Remove"
    'Assign end value to control
    Me.TransactionQty.SetFocus
    Me.TransactionQty = lngProductQty
    End If
    DoCmd.Save
    DoCmd.Close
    Else
    End If
    End Sub

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    There is no message box in that code, and there is also no open form action in that code.

    Does it only trigger the message when a button is pressed?

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Firstly you don't need to set focus on controls before setting their values, in fact it can lead to some undesired side effects(possibly your problem).

    You move to a new record after opening the form, if this forms sole purpose is to add records open it in Add mode instead.

    DoCmd.Save doesn't save your record, it saves any changes to the form.
    Use the records Dirty property to check if any changes have been made and save if needed;

    Code:
    If Me.Dirty Then Me.Dirty = False
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    I think it's because the form is being closed in the Load event. When you open a form, a sequence of events occurs Open>Load>Resize>Activate>Current. I believe if you close the form during one of these latter events, you'll get that message, which is probably why the Cancel for the Load event was provided. I think it's odd to close a form from any of these events for that form.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Are you saving calculated balance? Aggregate data should be calculated from raw data when needed. Review http://allenbrowne.com/AppInventory.html

    Where does the subtraction calc take place?

    Please post code snippets between CODE tags to retain indentation and readability, especially longer ones.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    I believe OP is showing wrong code. He describes problem occurs when button on form is clicked, which is not code shown.
    The code shown appends a three-field record to a table using a form as an untouched vector. I would have used an append query.

  7. #7
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101
    Thanks, davegri, that worked!

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    bbrazeau,

    How does davegri's suggestion resolve the issue as per the Title of your post
    how to keep or alter message displayed when code is run

    Could you tell us the issue and solution in simple terms?

  9. #9
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101
    Hi Orange,
    Short of it. It doesn't solve that problem directly, but by using his method the query makes a new entry in the "InventoryTransaction" table without the need to open/add record/close the form for doing so. See as davegri mentioned the code shown was not the button code, but the code that happens when the button on the form opens the "InventoryTransaction" form. So now that button just appends a new record to the "InventoryTransaction" table instead of opening, adding, then closing the form. I might add that there are 2 different forms I add records to the "InventoryTransaction' table from. One is OrderDetail (remove), and one is Production (add). See the DB is for an injection molding plant so we both sell and manufacture the products. I probably could have it automatically add and remove from inventory as orders are placed or production runs requested, but sometimes orders might be changed in between when they are placed and shipped so this gives the opportunity to hold off actually changing inventory until the order actually ships. Also sometimes production makes more or less than a run called for so this gives the opportunity to hold off until the run is done and QC ok's the qty to add to inventory.

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Thanks for the update --glad you have it working.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code for Message Box
    By Alex Motilal in forum Programming
    Replies: 4
    Last Post: 03-28-2018, 04:07 AM
  2. Get Write Conflict message due to my VBA code
    By mcomp72 in forum Programming
    Replies: 1
    Last Post: 11-07-2017, 01:41 AM
  3. Replies: 3
    Last Post: 10-23-2017, 02:09 PM
  4. Error message code
    By FJM in forum Access
    Replies: 11
    Last Post: 09-09-2013, 04:42 AM
  5. Alert Message Code Problem
    By 10 Gauge in forum Forms
    Replies: 1
    Last Post: 03-15-2011, 12:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums