Hi Benson,
Below You find an example for exporting data to an MySQL-database.
The only thing that differ from MS SQL 2000 is the connectionstring.
Code:
Option Explicit
Sub Export_Data_ADO__MySQL()
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnName As Range
Dim vaFName As Variant, vaEName As Variant
Dim i As Long
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets("Blad2")
With wsSheet
Set rnName = .Range("A2:" & .Range("A65536").End(xlUp).Address)
End With
vaFName = rnName.Offset(0, 1).Value
vaEName = rnName.Value
Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
cnt.ConnectionString = "DRIVER={MySQL};" _
& "SERVER=localhost;" _
& "DATABASE=XLDennis;" _
& "UID=;PWD=;OPTION=3;"
cnt.Open
rst.Open "SELECT * FROM tblnamn", cnt, adOpenDynamic, _
adLockOptimistic
For i = LBound(vaEName) To UBound(vaEName)
With rst
.AddNew
.Fields("FNamn") = vaFName(i, 1)
.Fields("ENamn") = vaEName(i, 1)
.Update
End With
Next i
rst.Close
Set rst = Nothing
cnt.Close
Set cnt = Nothing
End Sub
Following is a example of the connectionstring (it should be in one line only):
Code:
stCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs;Data Source=DENWAL"
BTW, You need to set a reference to teh MS ADO Object Library in the
VB-editor.
I´m not exactly sure what You mean by joining but above will get You started.
Kind regards,
Dennis