How to Quote Square Brackets in a Field Name for ADO Recordset's Filter Property

609 Views Asked by At

I am attempting to specify a filter condition on an ADO Recordset where one of the field names contains both left and right square brackets as part of the name. The resulting condition string is being assigned to the Recordset's Filter property so as to subset the data returned from the Recordset.

If the field name is "First Name" then simply enclosing the field name in square brackets works fine. For example:

recSet.Filter = "[First Name] = 'Tony'";

However, for a field name such as "Height [cm]" I have not been able to determine how to quote the square brackets within the field name. After searching the internet, things I have tried are:

recSet.Filter = "[Height [[]cm[]]] > 156"; 
recSet.Filter = "[Height [cm[]]] > 156"; 
recSet.Filter = "[Height [cm]]] > 156"; 

But none of these work.

Any suggestions on the correct way to handle such names?

Thanks, David.

BTW, I have no control over the names in the data tables being accessed.

1

There are 1 best solutions below

0
HexTheKiwi On

I contacted Microsoft and was told that you cannot use field names which contain square bracket characters in a Filter property. (There is no way to quote them at all.)

Their only suggestion was to rename the columns and then use the renamed columns.