I bought this book for Access VBA programming primarily to refresh my knowledge and learn some new stuff. I am currently try to learn how to use DSN-less connections. None of the examples work for me. I keep getting the "Data source name not found error".
Here is the code I'm using to connect to a text file:
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Set conn = New ADODB.Connection
'I get the error here.
conn.Open "DRIVER={Microsoft Text Driver(*.txt;*.csv)};" & _
"Dbq=" & CurrentProject.path & "\" & _
"Extensions=asc,csv,tab,txt"
Set rst = New ADODB.Recordset
rst.Open "Select * from [Employees.txt]", conn, adOpenStatic, _
adLockReadOnly, adCmdText
Do Until rst.EOF
For Each fld In rst.Fields
Debug.Print fld.Name & "=" & fld.Value
Next fld
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
The same thing occurs for other data sources as well, dBase and SQL Server. I've tried various changes and checked directories. Also checked to see if ODBC drivers are installed. Everything appears to be ok.
Can any one help me?
Thanks,
jmtitus
Here is the code I'm using to connect to a text file:
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Set conn = New ADODB.Connection
'I get the error here.
conn.Open "DRIVER={Microsoft Text Driver(*.txt;*.csv)};" & _
"Dbq=" & CurrentProject.path & "\" & _
"Extensions=asc,csv,tab,txt"
Set rst = New ADODB.Recordset
rst.Open "Select * from [Employees.txt]", conn, adOpenStatic, _
adLockReadOnly, adCmdText
Do Until rst.EOF
For Each fld In rst.Fields
Debug.Print fld.Name & "=" & fld.Value
Next fld
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
The same thing occurs for other data sources as well, dBase and SQL Server. I've tried various changes and checked directories. Also checked to see if ODBC drivers are installed. Everything appears to be ok.
Can any one help me?
Thanks,
jmtitus