I am getting a Run-Time Error '13': Type Mismatch. The Set db_data = NewConnection is what is highlighted in yellow. Would anyone know why this is happening? I got the code from: I am trying to learn how to import a csv file into a access table. Also is the DSN the location of where the csv files should be???
Thanks,
Darkhat01
Code:
Private Sub ImportData_Click()
MsgBox "The ID being used is: " & intID 'Error Check
MsgBox "Using dbFile: " & dbFile 'Error Check
Set db_data = NewConnection
db_data.CursorLocation = adUseClient
'Set up DSNless connection
db_data.Open "PROVIDER=MSDASQL;dsn=C:\MyDB Files;uid=;pwd=;database=;"
Set Ado_data = NewRecordset
'Note exactly the same select statement as would be used in a relational database
Ado_data.Open "select name, salary from employee.csv e, salary.csv s " & _
"where e.id=s.id", adOpenStatic, adLockOptimistic
If Ado_data.RecordCount < 1 Then
MsgBox "No data found"
Exit Sub
End If
'Go to the first record in the set and loop around till no more available
Ado_data.MoveFirst
For i = 0 To Ado_data.RecordCount - 1
MsgBox (Ado_data.Fields.Item(0).Value & " " & Ado_data.Fields.Item(1).Value)
Ado_data.MoveNext
Next
Ado_data.Close
db_data.Close
End Sub
Thanks,
Darkhat01