Hi JK,
Sure,
In the UF:
On Error GoTo Error_Sub
''' calling the UDF:
varRecordSet = RecordFilter(RecordSet, strSQl, strWhere, strWhereOperator, varWhereVal, _
strWhere1, strWhereOperator1, varWhereVal1, _
Headers, Me.chkIgnoreCase, Me.chkImportText, Me.opbAnd)
Exit_Sub:
Application.ScreenUpdating = True
Exit Sub
Error_Sub:
MsgBox Prompt:=Err.Number & " " & Err.Description, Title:=JPE_APP_TITLE
Resume Exit_Sub
End Sub
In the UDF:
Do Until RecordSet.EOF
ReDim Preserve arrData(dicFieldPos.Count - 1, lngRecords)
If intWherePos >= 0 Then ''' condition to evaluate
blnAddRecord = False
On Error GoTo AddRecord
Select Case strWhereOperator
Case "="
''' 3 conditions to evaluate
''' field should not be null
''' arithmetic compare if varWhereVal is numeric
''' string compare else
If Not IsNull(RecordSet.Fields(intWherePos)) Then
If IsNumeric(varWhereVal) Then
'If IsNumeric(RecordSet.Fields(intWherePos)) Then
If CDbl(RecordSet.Fields(intWherePos)) = CDbl(varWhereVal) Then blnAddRecord = True
'End If
Else
AddRecord:
On Error Resume Next
If blnAddRecord Then
For intFields = 0 To dicFieldPos.Count - 1
arrData(CLng(dicFieldPos.Keys(intFields)), lngRecords) = IIf(IsNull(RecordSet.Fields(dicFieldPos.Items(intFields))), "", CStr(Trim(RecordSet.Fields(dicFieldPos.Items(intFields)))))
If blnImportText And IsNumeric(arrData(CLng(dicFieldPos.Keys(intFields)), lngRecords)) Then arrData(CLng(dicFieldPos.Keys(intFields)), lngRecords) = Chr(39) & arrData(CLng(dicFieldPos.Keys(intFields)), lngRecords)
Next intFields
lngRecords = lngRecords + 1
End If
RecordSet.MoveNext
Loop
On Error GoTo 0
RecordFilter = arrData
Set dicFieldPos = Nothing
ActiveSheet.Columns.AutoFit
It is the bold line that bumps me out for the second record, passes for the first one.
The first record brings me to the AddRecord label, the second to the Error_Sub label. As said I found already a work-around with
If IsNumeric(RecordSet.Fields(intWherePos)) Then but it looks to me so strange that I don't see.
I could understand that my approach is not working for each record and bumps me out when evaluating the first record, in that case I would say I have a structural fault in the code but this is more looking as you are allowed to make one mistake.