I am trying to open an ADO connection & recordset. Having had some difficulty I downloaded some code in a small database and it worked. I opened a new DB file in access and copied the code across and it didn't work. Giving nme the same problem I started with.
I get the error: RunTime Error - 2147217900 Invalid SQL Statement; expected 'DELETE' 'INSERT' etc.
The downloaded data base that works I have called test good.mbd; the data base I opened & copied the data into I called test bad.mbd.
In opening the connections:
------ If I change the strConnection in test bad to reference test good.mdb it works and the form works, all the edits & updates work etc.
----- If I change the strConnection in test good.mdb to reference test bad.mdb the same error comes up.
The problem seems to be in the way my version of Access is opening the database. I have Office Pro XP and am running Access 2002.
Any suggestions -- I have tried almost everything except the one that works!!
Thanks
Stephen
The code from Test Bad.mbd (identical to Test Good.mdb apart from file reference) is:
Dim rsContacts As ADODB.Recordset
Dim cnCh5 As ADODB.Connection
Dim strConnection As String
Private Sub Form_Load()
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & "\Test Bad.mdb;"
'create a new connection instance and open it using the connection string
Set cnCh5 = New ADODB.Connection
cnCh5.Open strConnection
'create a new instance of a recordset
Set rsContacts = New ADODB.Recordset
'set various properties of the recordset
With rsContacts
'specify a cursortype and lock type that will allow updates
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
'open the recordset based on tblContacts table using the existing connection
.Open "tblContacts", cnCh5
'disconnect the recordset
.ActiveConnection = Nothing
'sort the recordset
.Sort = "txtLastName, txtFirstName, txtMiddleName"
End With
I get the error: RunTime Error - 2147217900 Invalid SQL Statement; expected 'DELETE' 'INSERT' etc.
The downloaded data base that works I have called test good.mbd; the data base I opened & copied the data into I called test bad.mbd.
In opening the connections:
------ If I change the strConnection in test bad to reference test good.mdb it works and the form works, all the edits & updates work etc.
----- If I change the strConnection in test good.mdb to reference test bad.mdb the same error comes up.
The problem seems to be in the way my version of Access is opening the database. I have Office Pro XP and am running Access 2002.
Any suggestions -- I have tried almost everything except the one that works!!
Thanks
Stephen
The code from Test Bad.mbd (identical to Test Good.mdb apart from file reference) is:
Dim rsContacts As ADODB.Recordset
Dim cnCh5 As ADODB.Connection
Dim strConnection As String
Private Sub Form_Load()
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & "\Test Bad.mdb;"
'create a new connection instance and open it using the connection string
Set cnCh5 = New ADODB.Connection
cnCh5.Open strConnection
'create a new instance of a recordset
Set rsContacts = New ADODB.Recordset
'set various properties of the recordset
With rsContacts
'specify a cursortype and lock type that will allow updates
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
'open the recordset based on tblContacts table using the existing connection
.Open "tblContacts", cnCh5
'disconnect the recordset
.ActiveConnection = Nothing
'sort the recordset
.Sort = "txtLastName, txtFirstName, txtMiddleName"
End With