ACC2002: ADO Filter Does Not Work with Fixed-Length Fields When You Use Microsoft Jet OLE DB Provider (286584)
The information in this article applies to:
- ActiveX Data Objects (ADO) 2.5
- Microsoft Access 2002
This article was previously published under Q286584 Advanced: Requires expert coding, interoperability, and multiuser
skills.
This article applies to a Microsoft Access database (.mdb) and to a
Microsoft Access project (.adp).
SYMPTOMS When you set the Filter property of an ActiveX Data Objects (ADO) recordset that is
opened with the Microsoft Jet OLE DB provider, no records are returned.
CAUSE You are filtering a fixed-length column, and you have MDAC
2.5 installed on the computer. RESOLUTIONInstall MDAC 2.6 on the Computer This problem has been corrected in MDAC 2.6. To resolve this
problem, upgrade your computer to MDAC 2.6. You can obtain the latest version
of MDAC at the following Microsoft Web site: To temporarily work around this problem, use one of the following
methods. Use a Client-Side Cursor You can work around this problem by opening the ADO recordset as
a client-side cursor rather than as a server-side cursor. To open the recordset
as a client-side cursor, set the CursorLocation property of the recordset to the constant adUseClient before you open it. The following is a code sample that opens the
recordset as a client-side cursor:
Sub ADOFilterTest()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source").Value = _
"C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb"
.Open
End With
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cn
.Source = "SELECT * FROM Customers"
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open
.Filter = "Country = 'USA'"
Debug.Print "Recordcount: " & .RecordCount
.Close
End With
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Use a Variable-Length Text Column You can also work around this problem by using a variable-length
text column in your table instead of a fixed-length text column. You can use a
SQL Data Definition Language (DDL) query to accomplish this. The following
sample code demonstrates how to alter a column's definition so that it is a
variable-length text column:
Sub AlterColumn()
Dim cn As ADODB.Connection
Dim strSQL As String
'SQL statement to change Country column to a
'15 character variable-length text column.
strSQL = "ALTER TABLE Customers ALTER COLUMN " & _
"Country VARCHAR(15)"
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source").Value = _
"C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb"
.Open
.Execute strSQL
'Update the Country field to strip out the trailing spaces.
strSQL = "UPDATE Customers SET Country = RTrim([Country])"
.Execute strSQL
.Close
End With
Set cn = Nothing
End Sub
STATUSMicrosoft
has confirmed that this is a problem in the Microsoft products that are listed
at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 5/9/2003 |
---|
Keywords: | kbbug kbnofix KB286584 |
---|
|