1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Private Sub Insert_Click()
Range("A2:D3").Select
Selection.ClearContents
Range("A2").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={MySQL ODBC 5.1 Driver};UID=root;;OPTION=35;PORT=3306;DATABASE=vb;SERVER=localhost;" _
, Destination:=Range("A2"))
.CommandText = Array("INSERT INTO tutorial VALUES ('" & Range("F1") & "', '" & Range("G1") & "', '" & Range("H1") & "', '" & Range("I1") & "')")
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=True
End With
End Sub |