When VBA executes rst.Open "Checks", conn, it pops up error:
Run-time error '-2147217900 (80040e14)'.
Option Compare Database
Option Explicit
Sub Open_AndRead_dBaseFile()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Provider=MSDASQL;DSN=Checks;"
Debug.Print conn.ConnectionString
Set rst = New ADODB.Recordset
rst.Open "Checks.dbf", conn
Do Until rst.EOF
Debug.Print rst.Fields(1).Value
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
End Sub
How to resolve the issue?
Faulty rst.Open "Checks", conn
-
- 2StarLounger
- Posts: 105
- Joined: 19 Apr 2010, 10:25
- Location: Hong Kong
Faulty rst.Open "Checks", conn
You do not have the required permissions to view the files attached to this post.
Regards,
Armstrong
Armstrong
-
- Administrator
- Posts: 78621
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Faulty rst.Open "Checks", conn
Try
rst.Open "Checks", conn, adOpenForwardOnly, adLockReadOnly, adCmdTableDirect
or
rst.Open "SELECT * FROM Checks", conn, adOpenForwardOnly, adLockReadOnly, adCmdText
rst.Open "Checks", conn, adOpenForwardOnly, adLockReadOnly, adCmdTableDirect
or
rst.Open "SELECT * FROM Checks", conn, adOpenForwardOnly, adLockReadOnly, adCmdText
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 105
- Joined: 19 Apr 2010, 10:25
- Location: Hong Kong
Re: Faulty rst.Open "Checks", conn
Hans,
Thanks for your help.
I solved the problem.
I chose a wrong driver. I should choose Microsoft dBase Drive (*.dbf) in ODBC Data Source Administrator window. Then, it works fine.
Thanks again.
Armstrong
Thanks for your help.
I solved the problem.
I chose a wrong driver. I should choose Microsoft dBase Drive (*.dbf) in ODBC Data Source Administrator window. Then, it works fine.
Thanks again.
Armstrong
Regards,
Armstrong
Armstrong
-
- Administrator
- Posts: 78621
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands