Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101


    Quote Originally Posted by davegri View Post
    As others suggest, debug.print and breakpoints are a very helpful set of debugging tools.
    Perhaps this will help with how to specifically use debug.print and breakpoints. Ctrl+G will show immediate window to view the debug.print results.

    Code:
    Private Sub cmdClose_Click()
    Dim rsGoodsLineItems As dao.Recordset
    Dim rsInventory As dao.Recordset
    Dim rsInventoryDetail As dao.Recordset
    Dim rsFaultyinventory As dao.Recordset
    Dim rsFaultyinventoryDetail As dao.Recordset
    Dim strQty As String
    Dim strSQL As String
    Dim strSQLF As String
    Dim strSQLCoS As String
    Dim strSQLCS As String
    Dim strSQLGIL As String
    DoCmd.OpenForm "frmProcessing", acNormal
      
       ' updates the costprice of item before posting
       DoCmd.SetWarnings False
            
      '     strSQLCoS = "UPDATE products " & vbCrL
      '     strSQLCoS = strSQLCoS & "       SET products.cost = [tblgoodsinlineitems].[cost]" & vbCrLf
      '     strSQLCoS = strSQLCoS & "       FROM products" & vbCrLf
      '     strSQLCoS = strSQLCoS & "       INNER JOIN tblgoodsinlineitems" & vbCrLf
      '     strSQLCoS = strSQLCoS & "       ON products.productID = [tblgoodsinlineitems].productID;"
    
    
      ' DoCmd.OpenQuery "qryGoodsInCostUpdate", acViewNormal ' legacy Access query
      
      Me.goodsintotal = Me.frmGoodsSub!txtGross
      Me.txtgoodsinnett = Me.frmGoodsSub!txtNett
      Me.txtgoodsinvat = Me.frmGoodsSub!txtVat
      DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
        
        Set rsGoodsLineItems = CurrentDb.OpenRecordset("tblgoodsinlineitems", dbOpenDynaset, dbSeeChanges)
        Set rsInventory = CurrentDb.OpenRecordset("tblinventory", dbOpenDynaset, dbSeeChanges)
        Set rsInventoryDetail = CurrentDb.OpenRecordset("tblinventorydetail", dbOpenDynaset, dbSeeChanges)
        Set rsFaultyinventory = CurrentDb.OpenRecordset("tblfaulty", dbOpenDynaset, dbSeeChanges)
        Set rsFaultyinventoryDetail = CurrentDb.OpenRecordset("tblfaultydetail", dbOpenDynaset, dbSeeChanges)
    
                'set breakpoint on line below
    
        If cbostocktype.value = 2 Then ' faulty
            strSQLGIL = "INSERT INTO tblfaultydetail ( qty" & vbCrLf
            strSQLGIL = strSQLGIL & "           , productID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , cost" & vbCrLf
            strSQLGIL = strSQLGIL & "           , unitsID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , name" & vbCrLf
            strSQLGIL = strSQLGIL & "           , rrp" & vbCrLf
            strSQLGIL = strSQLGIL & "           , Code" & vbCrLf
            strSQLGIL = strSQLGIL & "           , workingprice )SELECT tblgoodsinlineitems.qty" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.productID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.cost" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.unitsID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.name" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.rrp" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.Code" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.workingprice" & vbCrLf
            strSQLGIL = strSQLGIL & "        FROM tblgoodsinlineitems" & vbCrLf
            strSQLGIL = strSQLGIL & "       WHERE (((tblgoodsinlineitems.stockinID)=[forms]![frmGoodsReceipt]![txtStockinID]));"
            
            Debug.Print "Faulty strSQLGIL " & strSQLGIL
    
    
            strSQLCS = "UPDATE tblfaulty " & vbCrLf
            strSQLCS = strSQLCS & "  INNER JOIN tblfaultydetail " & vbCrLf
            strSQLCS = strSQLCS & "          ON tblfaulty.productID = tblfaultydetail.faultyID SET tblfaulty.Sumofqty = [tblfaulty]![SumOfqty]+[tblfaultydetail]![qty]" & vbCrLf
            strSQLCS = strSQLCS & "       WHERE (((tblfaultydetail.productID)=[tblfaulty]![faultyID]) " & vbCrLf
            strSQLCS = strSQLCS & "         AND ((tblfaultydetail.name)=[tblfaulty]![name]));"
    
    
            Debug.Print "Faulty strSQLCS " & strSQLCS
            
            DoCmd.SetWarnings False
            DoCmd.RunSQL strSQLGIL
            DoEvents
            
        ElseIf cbostocktype.value = 1 Then ' inventory
        
            strSQLGIL = "INSERT INTO tblinventorydetail ( qty" & vbCrLf
            strSQLGIL = strSQLGIL & "           , productID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , cost" & vbCrLf
            strSQLGIL = strSQLGIL & "           , unitsID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , name" & vbCrLf
            strSQLGIL = strSQLGIL & "           , rrp" & vbCrLf
            strSQLGIL = strSQLGIL & "           , Code" & vbCrLf
            strSQLGIL = strSQLGIL & "           , workingprice )SELECT tblgoodsinlineitems.qty" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.productID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.cost" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.unitsID" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.name" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.rrp" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.Code" & vbCrLf
            strSQLGIL = strSQLGIL & "           , tblgoodsinlineitems.workingprice" & vbCrLf
            strSQLGIL = strSQLGIL & "        FROM tblgoodsinlineitems" & vbCrLf
            strSQLGIL = strSQLGIL & "       WHERE (((tblgoodsinlineitems.stockinID)=[forms]![frmGoodsReceipt]![txtStockinID]));"
    
    
            Debug.Print "Inventory strSQLGIL " & strSQLGIL
    
    
            strSQLCS = "UPDATE tblinventory " & vbCrLf
            strSQLCS = strSQLCS & "  INNER JOIN tblinventorydetail " & vbCrLf
            strSQLCS = strSQLCS & "          ON tblinventory.productID = tblinventorydetail.productID SET tblinventory.Sumofqty = [tblinventory]![SumOfqty]+[tblinventorydetail]![qty]" & vbCrLf
            strSQLCS = strSQLCS & "       WHERE ((tblinventorydetail.productID)=[tblinventory]![ProductID]) " & vbCrLf
            strSQLCS = strSQLCS & "         AND ((tblinventorydetail.name)=[tblinventory]![name]);"
    
    
            Debug.Print "Inventory strSQLCS " & strSQLCS
            
            DoCmd.SetWarnings False
            DoCmd.RunSQL strSQLGIL
            DoEvents
            
        End If
        
            'set another breakpoint on line below
            
        If cbostocktype.value = 2 Then 'tblfaulty
            rsFaultyinventoryDetail.Close
            DoEvents
    
    
            Set rsFaultyinventoryDetail = CurrentDb.OpenRecordset("tblfaultydetail", dbOpenDynaset, dbSeeChanges)
    
    
                    If rsFaultyinventory.RecordCount > 0 Then
                            rsFaultyinventory.FindFirst "[faultyID]=" & rsFaultyinventoryDetail![productID]
                        If rsFaultyinventory.NoMatch = False Then
                            DoCmd.RunSQL strSQLCS
                  ElseIf rsFaultyinventory.NoMatch = True Then
                            DoCmd.OpenQuery "QryTempfaulty", acViewNormal
                        End If
                    End If
              If rsFaultyinventory.RecordCount = 0 Then
                 DoCmd.OpenQuery "QryTempfaulty", acViewNormal
               End If
            DoCmd.OpenQuery "QryDelTblFaultyDetail"
        'End If
    
    
        ElseIf cbostocktype.value = 1 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"
        End If
    
    
    rsInventory.Close
    rsInventoryDetail.Close
    rsGoodsLineItems.Close
    rsFaultyinventory.Close
    rsFaultyinventoryDetail.Close
    
    
    Set rsInventory = Nothing
    Set rsInventoryDetail = Nothing
    Set rsGoodsLineItems = Nothing
    Set rsFaultyinventory = Nothing
    Set rsFaultyinventoryDetail = Nothing
    
    
    DoCmd.Close acForm, "frmprocessing"
    DoCmd.Close
    End Sub
    Hi Dave, I have got the debug working now, but setting the break points, when it comes to the debug.print section, it goes straight past with nothing in the immediate window. I am getting info in the locals window, but lists every element of the database, which would be time consuming to look for detail in there!

  2. #17
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by Lesg View Post
    Hi Dave, I have got the debug working now, but setting the break points, when it comes to the debug.print section, it goes straight past with nothing in the immediate window. I am getting info in the locals window, but lists every element of the database, which would be time consuming to look for detail in there!
    If it does that, then it is NOT getting to that line?

    Use F8 !
    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. #18
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    OK guys, thanks for all your input, I have been able to resolve the problem now and it was due to the cbostocktype values being wrong, updating to the correct values has resolved and the stock control is now working again

  4. #19
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Lesg,

    You should have some message -whether driven from some flag you can set, or included in the code- to indicate that the Process has completed. Could be a message for successful completion and another within your error handling to indicate an error has occurred.
    I mention this because your testing/reporting wasn't showing anything (according to your posts).

    The locals window shows everything involved -- you can watch values change as you step through the code etc.
    Good luck.

    You'll have to resolve how/why cbostocktype values were wrong in an operational procedure.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Unable to step into code.
    By Homegrownandy in forum Programming
    Replies: 3
    Last Post: 08-09-2017, 08:40 AM
  2. Replies: 22
    Last Post: 07-18-2017, 01:05 AM
  3. Replies: 2
    Last Post: 10-21-2016, 11:26 AM
  4. Queries is my next step?
    By JPP in forum Queries
    Replies: 16
    Last Post: 02-25-2013, 12:36 PM
  5. Is There a Way to Debug or Step Through VB code?
    By jeffbase34 in forum Programming
    Replies: 1
    Last Post: 05-28-2009, 08:14 PM

Tags for this Thread

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