Say, my program is taking kind of long too run, mostly becasue of the size of the files being extracted. Still, the customer needs it to be quicker.

The code for sending the extracted items to the database is below. Does anyone see anything I can do to speed up the process. I realize its long and convoluted; but if anyone sees anything at first glance that I can do to speed thngs up, please let me know. Its a big section, so I'll break it in pieces. I really apprecaite it.

VB Code:
  1. Sub SendToDatabase()
  2. Dim rst As New ADODB.Recordset
  3. Dim cmd As ADODB.Command
  4. Dim dbAdd As Boolean
  5. Dim reopenRecordset As Boolean
  6. Dim sql As String
  7. Dim Characteristic As String
  8. Dim n As Integer
  9. Dim x As Long
  10. 'On Error GoTo stdhandler
  11. tr = 1
  12. 'subgroupitemcount = 0
  13. 'On Error Resume Next
  14. dbAdd = True
  15. pbimport.Enabled = True
  16. 'On Error GoTo handler
  17. reopenRecordset = True
  18. 'Create a connection object.
  19. Set cnn = CreateObject("ADODB.Connection")
  20.  
  21. 'Open a Microsoft Access database connection using the OLE DB connection string.
  22. cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & Trim(lbldatabase.Caption)
  23.  
  24. 'Open a Microsoft SQL Server Connection
  25. 'Provider=SQLOLEDB.1;Data Source=path to server
  26.  
  27. '***save assigned data into the appropriate database***
  28.  
  29. 'for each line of the code
  30. For x = 1 To xcount
  31.  
  32. 'PART NAME
  33.  
  34. ' First, check to see if the part already exists, by getting all partnames
  35. ' and seeing if any of them are the same as the variable 'partname'
  36. 'temppartname = partname
  37. 'temppartname = Replace(temppartname, "&", "and")
  38. temppartname = part(x)
  39. temppartname = Replace(temppartname, "&", "and")
  40. temppartname = Replace(temppartname, "#", "")
  41. temppartname = Replace(temppartname, Chr$(34), "")
  42. sourcesqlstatement = "Select PartName from Part where PartName <> ''"
  43. rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
  44. If rst.RecordCount > 0 Then
  45.     rst.MoveFirst
  46.     Do While Not rst.EOF
  47.         Value = rst.Fields("PartName")
  48.         If Value = temppartname Then
  49.             dbAdd = False
  50.             Exit Do
  51.          End If
  52.         rst.MoveNext
  53.     Loop
  54. End If
  55. rst.Close
  56.  
  57. 'Secondly, put the part into database, if necessary.
  58.     If dbAdd Then
  59.         lasteditdate = Now
  60.  
  61.         sql = "INSERT INTO Part (PartName, LastEditDate, GroupId) VALUES ('" & temppartname & "', '" & lasteditdate & "',-1)"
  62.        
  63.         cnn.Execute sql
  64.     End If
  65.     dbAdd = True
  66.  
  67. 'Thirdly, assign the id value for the part to a variable, so that it can be put in the characteristic table, if necessary.
  68. sourcesqlstatement = "Select PartId From Part Where PartName = '" & temppartname & "'"
  69. rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
  70.     If rst.RecordCount > 0 Then
  71.         rst.MoveFirst
  72.         dbAdd = True
  73.         Do While Not rst.EOF
  74.             partid = rst.Fields("PartId")
  75.             rst.MoveNext
  76.         Loop
  77.     End If
  78.     rst.Close
  79.  
  80. 'TRACE
  81. ' First, check to see if the trace name alreday exists, by getting all trace names
  82. ' and seeing if any of them are the same as the variable 'tracename'
  83. For t = 1 To tracecount
  84. sourcesqlstatement = "Select TraceId, TraceName from Trace where TraceName <> ''"
  85. rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
  86. dbAdd = True
  87. If rst.RecordCount > 0 Then
  88.     rst.MoveFirst
  89.     Do While Not rst.EOF
  90.         traceid(t) = rst.Fields("TraceId")
  91.         Value = rst.Fields("TraceName")
  92.         If Trim(UCase(Value)) = Trim(UCase(tracename(t))) Then
  93.             dbAdd = False
  94.             reopenRecordset = False
  95.             Exit Do
  96.          End If
  97.         rst.MoveNext
  98.     Loop
  99. End If
  100. rst.Close
  101.  
  102. 'Second, add any new trace name to the trace table.
  103. If dbAdd Then 'add trace name to Trace table if it doesn't already exist
  104.     sql = ""
  105.     temptracename = tracename(t)
  106.     temptracename = Replace(temptracename, "&", "and")
  107.     temptracename = Replace(temptracename, "#", "")
  108.     temptracename = Replace(temptracename, Chr$(34), "")
  109.     sql = "INSERT INTO Trace (TraceName, LastEditDate, GroupId, IsACCA, StoreTraceCodes) VALUES ('" & temptracename & "', '" & Now & "',-1,0,0)"
  110.     cnn.Execute sql
  111. End If
  112. latesttracename = tracename(t)
  113.  
  114. 'Thirdly, reopen the Trace table recordset, and extract the traceid of the latest
  115. 'trace name inserted, so that it can be inserted into TraceCodes and Data tables
  116. If reopenRecordset Then
  117.     sourcesqlstatement = "Select TraceId, TraceName from Trace where TraceName <> ''"
  118.     rst.Open sourcesqlstatement, cnn, adOpenStatic, adLockOptimistic
  119.     dbAdd = True
  120.     If rst.RecordCount > 0 Then
  121.         rst.MoveFirst
  122.         Do While Not rst.EOF
  123.             Value = rst.Fields("TraceName")
  124.             If Trim(UCase(latesttracename)) = Trim(UCase(Value)) Then
  125.                 traceid(t) = rst.Fields("TraceId") 'save these to check for adding trace codes later
  126.                 'tr = tr + 1
  127.                 Exit Do
  128.             End If
  129.             rst.MoveNext
  130.         Loop
  131.     End If
  132.     rst.Close
  133. End If
  134. Next t