import Excel worksheet to SQL Server table
On May 4, 12:49*am, ryguy7272
wrote:
Take a look at this and post back with the outcome:
Sub Rectangle1_Click()
'TRUSTED CONNECTION
* * On Error GoTo errH
* * Dim con As New ADODB.Connection
* * Dim rs As New ADODB.Recordset
* * Dim strPath As String
* * Dim intImportRow As Integer
* * Dim strFirstName, strLastName As String
* * Dim server, username, password, table, database As String
* * With Sheets("Sheet1")
* * * * * * server = .TextBox1.Text
* * * * * * table = .TextBox4.Text
* * * * * * database = .TextBox5.Text
* * * * * * If con.State < 1 Then
* * * * * * * * con.Open "Provider=SQLOLEDB;Data Source=" & server &
";Initial Catalog=" & database & ";Integrated Security=SSPI;"
* * * * * * * * 'con.Open
* * * * * * End If
* * * * * * 'this is the TRUSTED connection string
* * * * * * Set rs.ActiveConnection = con
* * * * * * 'delete all records first if checkbox checked
* * * * * * If .CheckBox1 Then
* * * * * * * * con.Execute "delete from tbl_demo"
* * * * * * End If
* * * * * * 'set first row with records to import
* * * * * * 'you could also just loop thru a range if you want.
|