When I start my application it downloads a bunch of data and slots it into listboxes and combo boxes. The main form has five tabs: head of, distributor, site, team, and parent company. Each of those five tabs has two listboxes and the data is pre-loaded into every one of those before the form is even displayed.

The problem I'm having is when the user changes from one tab to another. The code used to run very quickly, but I changed the way I connect to the database (at the request of the DBAs) and now create a new ADO connection when I need to access the DB and destroy it as soon as I'm done.

Switching between tabs does not need an ADO connection since the data is pre-loaded, but ever since I made this change that action has been very slow. Switching from one tab to another now takes 1-2 seconds which I think is too long. I can't figure out why it would take so long just looking at the code that's there. I put in breakpoints earlier and tested it; that is all that's being executed when the user goes from tab to tab. I'm scratching my head here.

This is the code that is executed when the user goes from one tab to another:

VB Code:
  1. Public Sub ClearGlobals()
  2.  
  3.     ' Clears app variables
  4.     appActiveTab = ""
  5.     appPrimInfoValue = ""
  6.     appReportSelected = ""
  7.     appAddInfoValue = ""
  8.     appAddInfoType = ""
  9.  
  10. End Sub

VB Code:
  1. Public Sub SetActiveTab()
  2.  
  3.     appActiveTab = GetActiveTabName()
  4.  
  5. End Sub

VB Code:
  1. Public Sub ResetLists()
  2.  
  3. ' Sets selections to false, i.e. if a value is selected on one
  4. ' tab, switching from one tab to another causes it to be de-selected
  5. With CriteriaSelection
  6.     .lstHeadOf.Text = ""
  7.     .lstHeadOfReport.Text = ""
  8.     .lstDist.Text = ""
  9.     .lstDistReport.Text = ""
  10.     .lstSite.Text = ""
  11.     .lstSiteReport.Text = ""
  12.     .lstTeamReport.Text = ""
  13.     .lstParentCompany.Text = ""
  14.     .lstPCompReport.Text = ""
  15.     .SubFilter.Text = ""
  16.     .SubFilterContents.Text = ""
  17. End With
  18.  
  19. End Sub

Code for GetActiveTabName():

VB Code:
  1. Public Function GetActiveTabName() As String
  2.  
  3.     Select Case GetActiveTabNumber()
  4.         Case Is = 0
  5.             GetActiveTabName = "HeadOf"
  6.         Case Is = 1
  7.             GetActiveTabName = "Distributor"
  8.         Case Is = 2
  9.             GetActiveTabName = "Site"
  10.         Case Is = 3
  11.             GetActiveTabName = "Team"
  12.         Case Is = 4
  13.             GetActiveTabName = "Parent"
  14.         Case Else
  15.             GetActiveTabName = ""
  16.     End Select
  17.    
  18. End Function