please let ME KNOW can i used CNTRL D in PROTECTED SHEET
Private Sub CommandButton1_Click()
Dim cnt As ADODB.Connection
Dim rst1 As ADODB.Recordset, rst2 As ADODB.Recordset
Dim stDB As String, stSQL1 As
String, stSQL2 As String
Dim strConn As String
Dim wbBook As Workbook
Dim Sheet1 As Worksheet
Dim i
Dim Target As Range
Dim column As Integer
Dim lnField As Long, lnCount As Long
Dim dataStr As String
'Instantiate the ADO-objects.
Set cnt = New ADODB.Connection
Set rst1 = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
Set wbBook = ThisWorkbook
Set Sheet1 = wbBook.Worksheets(1)
'Path to the database.
stDB = "mysql32"
'Create the connectionstring.
strConn = "Driver=MySQL ODBC 5.2 Unicode Driver;" _
& "Data Source=" & stDB & ";"
'The 1st raw SQL-statement to be executed.
'stSQL1 = "SELECT * FROM tblbatch_headers where idBatch " & batchID & "order by col_seq asc"
'The 2nd raw SQL-statement to be executed.
stSQL2 = "SELECT * FROM " & BMS.TextBox1 & " where FQR_User_Code='" & Environ("username") & _
"' and line_status in('QP')" '
'Clear the worksheet.
Sheet1.Range("A1:FA1").CurrentRegion.Clear
With cnt
.Open (strConn) 'Open the connection.
.CursorLocation = adUseClient 'Necessary to disconnect the recordset.
End With
With rst1
' .Open stSQL1, cnt 'Create the recordset.
Set .ActiveConnection = Nothing 'Disconnect the recordset.
End With
With rst2
.Open stSQL2, cnt 'Create the recordset.
Set .ActiveConnection = Nothing 'Disconnect the recordset.
End With
With Sheet1
' .Cells(2, 1).CopyFromRecordset rst1 'Copy the 1st recordset.
For i = 1 To rst2.Fields.Count
.Cells(2, i).Value = rst2.Fields(i - 1).Name
Next i
.Cells(3, 1).CopyFromRecordset rst2 'Copy the 2nd recordset.
End With
'If target.column < 16 Then
'Application.EnableEvents = False
' Application.Undo
'Application.EnableEvents = True
' MsgBox "You cannot do that!"
'End If
' End With
rst2.Close
Set rst2 = Nothing
cnt.Close
Set cnt = Nothing
'Release objects from the memory.
' rst1.Close
' Set rst1 = Nothing
ActiveSheet.Unprotect Password:="password"
Dim sh As Worksheet
Dim rng As AllowEditRange
Set sh = ActiveSheet
For Each rng In sh.Protection.AllowEditRanges
rng.Delete
Next rng
ActiveSheet.Protection.AllowEditRanges.Add Title:="Range1", Range:=Range("P1:BJ1000")
ActiveSheet.protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, AllowFormattingCells:=True, AllowUsingPivotTables:=True, AllowFormattingColumns:=True, userInterfaceOnly:=True, AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowSorting:=True
'ActiveCell.Select
'Selection.Font.Bold = True
'Colorize = myValue
Unload Me
End Sub
Private Sub UserForm_Click()
End Sub
Bookmarks