Results 1 to 5 of 5
  1. #1
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101

    Step through Queries to find errors help

    Hi Guys,

    I have an issue when I am updating an inventory table (tblInventory), from a Purchase Order (PO), in that if an Item of the PO is not currently in tblInventory, I use the following code to add the item:

    Code:
        If cbostocktype.value = 4 Then ' tblinventory
            rsInventoryDetail.Close
            DoEvents
    
    
        Set rsInventoryDetail = CurrentDb.OpenRecordset("tblinventorydetail", dbOpenDynaset, dbSeeChanges)
    
    
    
    
           If rsInventory.RecordCount > 0 Then
                    rsInventory.FindFirst "[ProductID]=" & rsInventoryDetail![productID]
                If rsInventory.NoMatch = False Then
                         DoCmd.RunSQL strSQLCS
                  ElseIf rsInventory.NoMatch = True Then
                         DoCmd.OpenQuery "qryTemp", acViewNormal
                End If
             End If
              If rsInventory.RecordCount = 0 Then
                 DoCmd.OpenQuery "qryTemp", acViewNormal
               End If
            DoCmd.OpenQuery "qryDeltblCSDetail"
    However, I found that items that are not currently in tblInventory, items are not being added as I had expected, so I want to be able to stop the process and check why the items are not being added?

    qryTemp is an append query, that should add any items of the PO to tblInventoryDetail, which in turn updates the qty of items in tblInventory.



    Hope that makes sense and any advise is appreciated.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You would need to read the recordset again, I would have thought. It is not dynamic. At least I do not think so , despite that dbseechanges unless you are using SQLServer, which I have never used.

    https://www.google.com/search?q=dbse...hrome&ie=UTF-8

    You could try the RecordsAffected property?

    https://learn.microsoft.com/en-us/of...d-property-dao

    Plus I thought you needed Execute on updatable queries?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Welshgasman View Post
    You would need to read the recordset again, I would have thought. It is not dynamic. At least I do not think so , despite that dbseechanges unless you are using SQLServer, which I have never used.

    https://www.google.com/search?q=dbse...hrome&ie=UTF-8

    You could try the RecordsAffected property?

    https://learn.microsoft.com/en-us/of...d-property-dao

    Plus I thought you needed Execute on updatable queries?
    Thanks for your feedback, the tblInventorydetail is a 'local' access table, that is cleared once the update has cleared. tblInventory is however, an SQL table, but from my testing, I am seeing the the tblInventoryDetail is created correctly, its just the qryTemp that is not being executed. I have tested the qryTemp once tblInventoryDetail is created??

    Can you clarify what you are saying about the 'Execute on updatable Queries' are you saying I should change line:

    Code:
    ElseIf rsInventory.NoMatch = True Then
                         DoCmd.OpenQuery "qryTemp", acViewNormal ' change this ?

  4. #4
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    So after extensive testing to identify the issue, it looks like this is caused by field 'SumofQty' in tblInventory for products that were not updating, if they existed in the table, was dues to having a value of null.

    I am not sure how these got a null value, so need to investigate further on that.

    But then also need to figure out why the qryTemp is not adding any items to tblInventory via the if statatments:

    Code:
    If rsInventory.RecordCount > 0 Then
                    rsInventory.FindFirst "[ProductID]=" & rsInventoryDetail![productID]
                If rsInventory.NoMatch = False Then
                         DoCmd.RunSQL strSQLCS
                  ElseIf rsInventory.NoMatch = True Then
                         DoCmd.OpenQuery "qryTemp", acViewNormal
                End If
             End If
              If rsInventory.RecordCount = 0 Then
                 DoCmd.OpenQuery "qryTemp", acViewNormal
               End If
            DoCmd.OpenQuery "qryDeltblCSDetail"

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Start indenting your code properly.
    That helps a lot when trying to identify logic errors.

    Code:
    If rsInventory.RecordCount > 0 Then
        rsInventory.FindFirst "[ProductID]=" & rsInventoryDetail![productID]
        If rsInventory.NoMatch Then
            DoCmd.OpenQuery "qryTemp", acViewNormal
        Else
            DoCmd.RunSQL strSQLCS
        End If
    Else
        DoCmd.OpenQuery "qryTemp", acViewNormal
    End If
    DoCmd.OpenQuery "qryDeltblCSDetail"
    Next step is to walk your code and see what it is doing, not what you think it s doing.
    Try the queries on their own in the QBE window
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 18
    Last Post: 01-26-2022, 08:02 AM
  2. Step by Step viewing Submit Button actions
    By farmer4H in forum Forms
    Replies: 27
    Last Post: 07-23-2019, 05:10 PM
  3. Replies: 22
    Last Post: 07-18-2017, 01:05 AM
  4. Replies: 2
    Last Post: 10-21-2016, 11:26 AM
  5. Queries is my next step?
    By JPP in forum Queries
    Replies: 16
    Last Post: 02-25-2013, 12:36 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