derekroger
New member
- Local time
- Tomorrow, 04:42
- Joined
- Apr 15, 2010
- Messages
- 8
Hi There,
So I have come to a roadblock regarding recordset filtering.
I have a sub procedure that creates a clone of the form's recordset to check that at least one record matches the filter criteria before it is applied to the form (to avoid errors):
Public Sub sub_CheckRecordCount()
On Error GoTo eh:
Dim rs As Recordset
Set rs = Me.Recordset.Clone
mbIsOKToFilter = True
With rs
.Filter = msFilter
If .RecordCount = 0 Then
mbIsOKToFilter = False
MsgBox "Sorry, there are no records that match the specified criteria.", vbExclamation, "No Records"
End If
End With
ex:
Set rs = Nothing
Exit Sub
eh:
MsgBox "Error '" & Err.Description & "' in procedure sub_CheckRecordCount of Form frmExtract"
Resume ex
Now this works perfectly for most filter strings. But as soon as my filter string look a little like the following (i.e. 2 levels of conditions) ...
(Field1 = 1 OR Field2 = 1 OR Field3 = 1) AND (Field4 = -1)
... an error occurs. And the odd thing is, this exact filter string works seamlessly on the actual recordset - it's only the clone that throws an error.
So I'm at my wits end at the moment ... any help would be greatly appreciated.
So I have come to a roadblock regarding recordset filtering.
I have a sub procedure that creates a clone of the form's recordset to check that at least one record matches the filter criteria before it is applied to the form (to avoid errors):
Public Sub sub_CheckRecordCount()
On Error GoTo eh:
Dim rs As Recordset
Set rs = Me.Recordset.Clone
mbIsOKToFilter = True
With rs
.Filter = msFilter
If .RecordCount = 0 Then
mbIsOKToFilter = False
MsgBox "Sorry, there are no records that match the specified criteria.", vbExclamation, "No Records"
End If
End With
ex:
Set rs = Nothing
Exit Sub
eh:
MsgBox "Error '" & Err.Description & "' in procedure sub_CheckRecordCount of Form frmExtract"
Resume ex
Now this works perfectly for most filter strings. But as soon as my filter string look a little like the following (i.e. 2 levels of conditions) ...
(Field1 = 1 OR Field2 = 1 OR Field3 = 1) AND (Field4 = -1)
... an error occurs. And the odd thing is, this exact filter string works seamlessly on the actual recordset - it's only the clone that throws an error.
So I'm at my wits end at the moment ... any help would be greatly appreciated.