while updating data it takes to much time to update

user231

New Member
Joined
Jan 8, 2015
Messages
7
while updating data it takes to much time to update i have data in excel something 2000 rows and columns 40


Code:
Private Sub CommandButton1_Click()


Dim dbconn As New ADODB.Connection
Dim stDB, strConn


Dim totColumns, totRows, i, j, BMS_id, UpdateprBatchName, List, Msg
Dim prBatchName, prTableQry, inTableQry, prTableQry1, dbQry
Dim rs As New ADODB.Recordset


 'Path to the database.
    stDB = "mysql32"


     'Create the connectionstring.
    strConn = "Driver=MySQL ODBC 5.2 Unicode Driver;" _
    & "Data Source=" & stDB & ";"
'With Sheet1
''Application.ScreenUpdating = True
'Cells.Locked = False
'    Application.ScreenUpdating = False
'    ActiveSheet.Unprotect "ka09z2507"
'   ' unlock all the cells
'   ' Selection.Locked = False
'    Dim foundCol As Range
'    Dim response As Variant
'    response = Array("Itemnum", _
'                     "BMS_ID", _
'                     "FQR_User_code", _
'                     "Original Mfr Name", _
'                     "Original Mfr Part No", _
'                     "ORIGINAL SUPPLIER NAME", _
'                     "ORIGINAL SUPPLIER PART #", _
'                     "Original Description", _
'                     "Original Description 2", _
'                     "NOUN", _
'                     "MODIFIER", _
'                     "ATTRIBUTE NAME 1", _
'                     "ATTRIBUTE NAME 2", _
'                     "ATTRIBUTE NAME 3", _
'                     "ATTRIBUTE NAME 4", _
'                     "ATTRIBUTE NAME 5", _
'                     "ATTRIBUTE NAME 6", _
'                     "ATTRIBUTE NAME 7", _
'                     "ATTRIBUTE NAME 8", _
'                     "ATTRIBUTE NAME 9", _
'                     "ATTRIBUTE NAME 10", _
'                     "ATTRIBUTE NAME 11", _
'                     "ATTRIBUTE NAME 12", _
'                     "ATTRIBUTE NAME 13")
'    For Each res In response
'    Set foundCol = ActiveSheet.Rows(2).Find(res, LookIn:=xlValues, lookat:=xlColumns)
'    Selection.Locked = True
'    If Not foundCol Is Nothing Then
'        ' Cells.Locked = True
'      foundCol.EntireColumn.Locked = True
'    Else
'        MsgBox ("Column not found.")
'    End If
'    Next
'    ActiveSheet.Protect "ka09z2507"
'    Application.ScreenUpdating = True
'End With
     
Sheet1.Activate
'prBatchName = "tblprod_agr_007"


totColumns = ActiveSheet.Cells(2, 1).CurrentRegion.Columns.Count
totRows = ActiveSheet.Cells(3, 1).CurrentRegion.Rows.Count


 'prBatchName = ActiveSheet.Cells(3, totColumns + 1).Values
dbconn.Open strConn
rs.CursorLocation = adUseServer
rs.Open "select * from " & update.txt1, dbconn, adOpenStatic, adLockOptimistic
    For j = 3 To totRows + 1
       BMS_id = ActiveSheet.Cells(j, 1)
        rs.Find "BMS_ID='" & BMS_id & "'"
        
        For i = 2 To totColumns
        rs(ActiveSheet.Cells(2, i).Value) = ActiveSheet.Cells(j, i)
        Next
        rs.update
          Next
rs.Close
dbconn.Close
Application.ScreenUpdating = True
       
MsgBox "Data updated sucessfully"


 Cells.Locked = False
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect "ka09z2507"
   ' unlock all the cells
   ' Selection.Locked = False
   ' Dim foundCol As Range
   ' Dim response As Variant
    response = Array("Itemnum", _
                     "BMS_ID", _
                     "FQR_User_code", _
                     "Original Mfr Name", _
                     "Original Mfr Part No", _
                     "ORIGINAL SUPPLIER NAME", _
                     "ORIGINAL SUPPLIER PART #", _
                     "Original Description", _
                     "Original Description 2", _
                     "NOUN", _
                     "MODIFIER", _
                     "ATTRIBUTE NAME 1", _
                     "ATTRIBUTE NAME 2", _
                     "ATTRIBUTE NAME 3", _
                     "ATTRIBUTE NAME 4", _
                     "ATTRIBUTE NAME 5", _
                     "ATTRIBUTE NAME 6", _
                     "ATTRIBUTE NAME 7", _
                     "ATTRIBUTE NAME 8", _
                     "ATTRIBUTE NAME 9", _
                     "ATTRIBUTE NAME 10", _
                     "ATTRIBUTE NAME 11", _
                     "ATTRIBUTE NAME 12", _
                     "ATTRIBUTE NAME 13")
    For Each res In response
    Set foundCol = ActiveSheet.Rows(2).Find(res, LookIn:=xlValues, lookat:=xlColumns)
    Selection.Locked = True
    If Not foundCol Is Nothing Then
        ' Cells.Locked = True
      foundCol.EntireColumn.Locked = True
'    Else
'        MsgBox ("Column not found.")
    End If
    Next
    ActiveSheet.Protect "ka09z2507"
    Application.ScreenUpdating = True
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, Password:="ka09z2507", AllowFiltering:=True, AllowFormattingCells:=True, AllowUsingPivotTables:=True, AllowFormattingColumns:=True, userInterfaceOnly:=True, AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True
        


Unload update
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,277
Messages
6,171,149
Members
452,382
Latest member
RonChand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top