slow form display

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #1

    slow form display

    I'm using Access 2000 (and also 2003 with same result) in a Windows XP Professional environment on a peer-to-peer network. Files in this system are relatively small. There are about 1,200 rows in the item/warehouse table, about 200 order headers, and about 2000 order detail rows.

    I have a form with a sub-form in the detail of the main form. The sub-form is a continuous line display (not single item); In the heading I am getting a customer's order heading information, and in the subform I am listing all of the line items for that order.

    Each line in the subform has a text box for inventory item number, quantity ordered, quantity shipped, on hand quantity, and on order quantity (all open orders combined).

    If the order quantity for that item exceeds the (on hand - on order) then there are not enough available for that order and I use conditional formatting to turn the background of the on hand text box yellow.

    The problem is, sometimes this form is VERY slow to complete. The on hand and on order boxes remain empty, filling down the screen slowly. And oddly, if you do an ALT-TAB to switch out of the screen, and ALT-TAB back immediately, then suddenly all the text boxes are filled in. Or, if you wave your mouse over an empty text box, the value for that text box will appear.

    The on-hand quantity is not a single field, there can be on hand in more than one warehouse.Here is the code to return the on hand value for an item
    Code:
    Public Function CalcOnHand(ItemNbr As String) As Long
    Dim db As Database
    Dim rs As DAO.Recordset
    Dim qd As QueryDef
    Dim Sql As String
    Dim strFind As String
    
    Dim Onhandqty, Counter As Integer
    Counter = 0
    
    Set db = CurrentDb
        
        Set rs = db.OpenRecordset("ItemWarehouse")
        Onhandqty = 0
        On Error GoTo Loopend
        rs.MoveFirst
        
        strFind = "Item='" & CStr(ItemNbr) & "'"
        rs.FindFirst (strFind) ' first occurrence of this item in itemwh file
        
    LoopItems:
        While (Not (rs.EOF))
        If rs.NoMatch Then GoTo Loopend
        If rs![Item] <> ItemNbr Then GoTo NextItem
        ' If rs![Warehouse] <> "9301" And rs![Warehouse] <> "3405" Then GoTo NextItem
        If rs![Warehouse] = "PCR" Then GoTo NextItem
        Counter = Counter + 1
        Onhandqty = Onhandqty + rs![OnHand]
        If Counter > 1 Then GoTo Loopend  'don't bother looking after we found both warehouses
    NextItem:
        rs.FindNext (strFind)
        
        'rs.MoveNext
        Wend
        'GoTo LoopItems
    
    Loopend:
       CalcOnHand = Onhandqty
        rs.Close
        Set rs = Nothing
    
    End Function
    The code to get the on order quantity comes from a query, and it is like this
    Code:
    SELECT tbl_Orders.OHCustomerID, tbl_Orders.OHOrderDate, tbl_Orders.OHOrderNbr, tbl_Orders.OHPONumber, tbl_Orders.OHCasesPerPallet, tbl_Orders.OHMemo, tbl_Orders.OHStatus, tbl_Orders.OHCarrier, tbl_Orders.OHTotalWeight, tbl_Orders.OHPalletCount, tbl_Orders.OHShipDate, tbl_Orders.OHBOL, tbl_Orders.OHInvoice, tbl_Orders.OHTerms, tbl_Orders.OHCHSequence, tbl_Orders.OHCases, tbl_Orders.OHCartons, tbl_Orders.OHCigarettes, tbl_Orders.OHDiscPct, tbl_Orders.OHDueDate, tbl_Orders.OHMessage, tbl_Orders.OHFreightCharge, tbl_Orders.OHMiscCharge
    FROM tbl_Orders
    ORDER BY tbl_Orders.OHOrderDate DESC , tbl_Orders.OHOrderNbr DESC;
    What's going on and how to I correct it?
    Thanks,
    Jim
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Try this instead:

    Code:
     
    Public Function CalcOnHand(ItemNbr As String) As Long
    Dim db As Database
    Dim rs As DAO.Recordset
    Dim Onhandqty As Integer
     
    Onhandqty = 0
     
    Set db = CurrentDb
    Set rs = db.OpenRecordset("ItemWarehouse")
     
    rs.MoveFirst
    Do until rs.EOF
      If rs!Item = CStr(ItemNbr) Then 
    	If rs![Warehouse = "9301" Then 
    	  If rs![Warehouse] = "3405" Then 
    		If rs![Warehouse] <> "PCR" Then
    		  Onhandqty = Onhandqty + rs![OnHand]
    		  rs.MoveLast
    		End If 
    	  End If   
    	End If 
      End If   
      rs.MoveNext
    Loop
     
    Loopend:
    CalcOnHand = Onhandqty
    rs.Close
    Set rs = Nothing
    Set db = Nothing
     
    End Function

    Comment

    • jimatqsi
      Moderator Top Contributor
      • Oct 2006
      • 1293

      #3
      Thanks for the reply, MM. I've learned a lot by reading your responses to a lot of questions here. I've very glad there are some folks with so much knowledge and willingness to share it.

      In this case, it appears you're suggesting I change to a sequential read through the ItemWarehouse table. Seems to me that will make it less fast. But I'll give it a shot, I don't have any better ideas.

      Thanks,
      Jim

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Hi Jim

        Because of the way the Jet Engine works this is not always the case.

        With the code I have given you the sequential logic means that the search will jump to the next set of records once the required result is found.

        If a condition is untrue it will automatically jump to the next record.

        I think you'll be surprised at how fast it will run.

        Originally posted by jimatqsi
        Thanks for the reply, MM. I've learned a lot by reading your responses to a lot of questions here. I've very glad there are some folks with so much knowledge and willingness to share it.

        In this case, it appears you're suggesting I change to a sequential read through the ItemWarehouse table. Seems to me that will make it less fast. But I'll give it a shot, I don't have any better ideas.

        Thanks,
        Jim

        Comment

        • jimatqsi
          Moderator Top Contributor
          • Oct 2006
          • 1293

          #5
          MM,
          Thanks, but the change you suggested did not make any difference. It's really odd, they way the text boxes in the "on hand" column will fill in if you wave the mouse over them. And if you Alt/Tab to another window, and Alt/Tab back immediately, they're all filled in.

          I'm going to try to get the on hand value from a query and link the text box to the query result.

          Jim

          Comment

          • jimatqsi
            Moderator Top Contributor
            • Oct 2006
            • 1293

            #6
            I have changed to get the on hand quantity from a query, but still I have this problem.

            Here's a little more information. Hoping I can give enough info so that somebody will recognize what is going on here.

            My form is an order entry form. The heading of the main form has customer data, the subform has order details. When I launch the form, the first customer appears and his most recent order. Usually orders consist of at least 4 or 5 line items. Each line item shows the item number, order quantity, ship quantity, and the quantity on hand for that item. Sometimes the first line item has the on hand value filled in, sometimes not, but the other lines always have a blank in the on hand text box. Eventually, slowly, they fill in. (All the other text boxes on all the lines filled in immediately upon entering the form, as is normal.)

            You can go to other customers, other orders, and the problem persists.

            If you wave your mouse over the top most blank text box, the quantity on order will fill in. If you wave at a lower blank text box, nothing happens. If you Alt/Tab out of that screen, and immediately Alt/Tab back, all the blanks fill instantly.

            Whether you fill in the boxes by doing an alt/tab, or by progressively moving down the screen with your mouse, after all the boxes have been filled in for any one order, there is no longer any problem. You can navigate to other customers and other orders, and everything fills in very quickly.

            Any ideas?

            Thanks,
            Jim

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              Open the subform on its own in design view.

              Go to the OnHand textbox and open the properties window.

              Check the data tab and look at the control source and default value for this control. What are they set to.

              Are there filter values set?

              Then go to the Event tab and check if there are macros or event procedures running on any events, if so what are they?

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                BTW

                Where and when are you calling the CalcOnHand function?

                Comment

                • jimatqsi
                  Moderator Top Contributor
                  • Oct 2006
                  • 1293

                  #9
                  MM,
                  No events, no default and no filters. The countrol source for the text box is
                  =CalcOnHand([OdItem])
                  where OdItem is the Inventory Item number for the line item.

                  Jim

                  Comment

                  • MMcCarthy
                    Recognized Expert MVP
                    • Aug 2006
                    • 14387

                    #10
                    Originally posted by jimatqsi
                    MM,
                    No events, no default and no filters. The countrol source for the text box is
                    =CalcOnHand([OdItem])
                    where OdItem is the Inventory Item number for the line item.

                    Jim


                    OK take that value out of there and leave it blank

                    Then in the OnLoad Event of the form


                    Code:
                     
                    Private Form_OnLoad()
                     
                    Me.OnHand=CalcOnHand(Me.OdItem)
                     
                    End Sub

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      Originally posted by mmccarthy
                      OK take that value out of there and leave it blank

                      Then in the OnLoad Event of the form

                      I mean the subform on load event by the way.

                      Comment

                      • jimatqsi
                        Moderator Top Contributor
                        • Oct 2006
                        • 1293

                        #12
                        Thanks, MM, I can't wait to try that. Seems then that the entire recordset is loaded and each related text box calculate at the start of the form. What does that mean about updates to the data during processing ... if the user enters this order entry form at the start of the business day, and stays in it all day, does the form data need refreshed in order for the correct on hand quantities to show?

                        More specifically, when this screen is used to ship some units, will the form show the new on hand amount correctly? Or rather, what steps have to be taken to insure that it does show the right quantity on hand?

                        Thanks,
                        Jim

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #13
                          If any changes take place to data that will have an effect on the calculation of the OnHand control then it will have to be retriggered.

                          Are we talking about changes in the same form or elsewhere in the database.

                          Comment

                          • jimatqsi
                            Moderator Top Contributor
                            • Oct 2006
                            • 1293

                            #14
                            Changes to on hand could be made from this form and from other activities by other users performing the same process, or other processes.

                            Originally posted by mmccarthy
                            If any changes take place to data that will have an effect on the calculation of the OnHand control then it will have to be retriggered.

                            Are we talking about changes in the same form or elsewhere in the database.

                            Comment

                            • MMcCarthy
                              Recognized Expert MVP
                              • Aug 2006
                              • 14387

                              #15
                              Originally posted by jimatqsi
                              Changes to on hand could be made from this form and from other activities by other users performing the same process, or other processes.
                              Is OnHand a field bound to any table or just a calculation for display purposes.

                              Comment

                              Working...