Results 1 to 2 of 2
  1. #1
    theperson is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2012
    Posts
    28

    Optimize my VBA code

    I have the following code below that works fine, but I recently moved my tables to Azure and now it takes forever to complete. Can you guys see any obvious code optimizations that might help speed things up?



    Code:
    Private Sub Command4_Click()
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
    
        stDocName = "Inventory Base1"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
        
    Counter = 1
    DoCmd.GoToRecord , , acLast
    lastpart = Forms![Inventory Base1]![Part#]
    
    
    Do
        DoCmd.GoToRecord , , acGoTo, Counter
        Currentpart = Forms![Inventory Base1]![Part#]
        Forms![Inventory Base1]![Calculated Average Volume] = 0
        Forms![Inventory Base1]![Future Inventory] = Forms![Inventory Base1]![Inventory-Current]
        Forms![Inventory Base1]![Days of Inv] = 1000
        Forms![Inventory Base1]![Days of Inv minus orders] = 1000
        Counter = Counter + 1
    Loop Until Currentpart = lastpart
        
        
        DoCmd.OpenForm "Ave volume per month"
        Counter = 1
        DoCmd.GoToRecord , , acLast
        lastpart = Forms![Ave Volume per month]![Part#]
        
        Do
            DoCmd.OpenForm "Ave volume per month"
            DoCmd.GoToRecord , , acGoTo, Counter
            Part1 = Forms![Ave Volume per month]![Part#]
            Volume = Forms![Ave Volume per month]![Volumepermonth]
            DoCmd.OpenForm "Inventory Base1"
            Forms![Inventory Base1]![Part#].SetFocus
            DoCmd.FindRecord Part1
            Forms![Inventory Base1]![Calculated Average Volume] = Volume
            Counter = Counter + 1
        Loop Until Part1 = lastpart
        
        DoCmd.OpenForm "Future Inventory"
        Counter = 1
        DoCmd.GoToRecord , , acLast
        lastpart = Forms![Future Inventory]![Part#]
        
        Do
            DoCmd.OpenForm "Future Inventory"
            DoCmd.GoToRecord , , acGoTo, Counter
            Part1 = Forms![Future Inventory]![Part#]
            Volume = Forms![Future Inventory]![Future Inv]
            DoCmd.OpenForm "Inventory Base1"
            Forms![Inventory Base1]![Part#].SetFocus
            DoCmd.FindRecord Part1
            Forms![Inventory Base1]![Future Inventory] = Volume
            Counter = Counter + 1
        Loop Until Part1 = lastpart
        
    DoCmd.OpenForm "Inventory Base1"
    Counter = 1
    DoCmd.GoToRecord , , acLast
    lastpart = Forms![Inventory Base1]![Part#]
    
    
    Do
        DoCmd.GoToRecord , , acGoTo, Counter
        Currentpart = Forms![Inventory Base1]![Part#]
        If Forms![Inventory Base1]![Calculated Average Volume] > 0 Then
            Forms![Inventory Base1]![Days of Inv] = 30 * Forms![Inventory Base1]![Inventory-Current] / Forms![Inventory Base1]![Calculated Average Volume]
            Forms![Inventory Base1]![Days of Inv minus orders] = 30 * Forms![Inventory Base1]![Future Inventory] / Forms![Inventory Base1]![Calculated Average Volume]
        Else
        End If
        Counter = Counter + 1
    Loop Until Currentpart = lastpart
    
    
    DoCmd.Close acForm, "Inventory Base1"
    DoCmd.Close acForm, "Future Inventory"
    DoCmd.Close acForm, "Ave Volume per month"
    
    
        stDocName = "tentative schedule"
        DoCmd.OpenReport stDocName, acNormal
    
    
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I don't have any experience with Azure, but I found this via Google.
    FMS Access/Azure
    Hope it's helpful.

    Most Access developers will tell you to avoid naming conventions that use embedded spaces or special characters (eg #$&... in names)

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

Similar Threads

  1. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  2. Code to drop tables and optimize database on closure
    By registoni in forum Programming
    Replies: 4
    Last Post: 09-25-2013, 12:53 PM
  3. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  4. Replies: 1
    Last Post: 11-16-2011, 11:56 PM
  5. Optimize a select query
    By accessnewb in forum Queries
    Replies: 15
    Last Post: 07-21-2011, 01:22 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