Great fun
Using your table, I have created an additional field called PhilsPx to compare results.
I also have a form with a command button called "DoScanThin g" for testing.
This is the code
It is not particularly elegant, but seems to produce the correct results, and you need to remove the Debug statements.
Phil
Using your table, I have created an additional field called PhilsPx to compare results.
I also have a form with a command button called "DoScanThin g" for testing.
This is the code
Code:
Private Sub DoScanThing_Click() Dim MyDb As Database Dim ScanSet As Recordset Dim StrSQL As String Dim StrSearchFor() As String Dim StrSearchIn() As String Dim i As Integer, j As Integer, k As Integer StrSQL = "SELECT Scan.* FROM SCAN ORDER BY ID" Set MyDb = CurrentDb Set ScanSet = MyDb.OpenRecordset(StrSQL) With ScanSet Do Until .EOF .Edit !PhilsPX = Null .Update .MoveNext Loop .MoveFirst Do Until .EOF Debug.Print !ID; " "; 'If !ID = 304 Then Stop StrSearchFor = Split(!Em, ",") For i = 0 To UBound(StrSearchFor) StrSearchFor(i) = Trim(StrSearchFor(i)) Debug.Print StrSearchFor(i); " "; Next i Debug.Print "PX: "; StrSearchIn = Split(!Pxbefore, " ,") For j = 0 To UBound(StrSearchIn) StrSearchIn(j) = Trim(StrSearchIn(j)) Debug.Print StrSearchIn(j); " "; Next j 'Look for match .Edit For j = 0 To UBound(StrSearchIn) For i = 0 To UBound(StrSearchFor) k = InStr(StrSearchIn(j), StrSearchFor(i)) If k > 0 Then ' Match found 'Stop StrSearchIn(j) = Replace(StrSearchIn(j), StrSearchFor(i), "") !PhilsPX = !PhilsPX & Trim(StrSearchIn(j)) End If Next i Next j .Update .MoveNext Debug.Print Loop .Close Set ScanSet = Nothing End With ' Now go through again and add the unchanged values StrSQL = "SELECT Scan.* FROM SCAN WHERE IsNull(PhilsPX) ORDER BY ID" Set ScanSet = MyDb.OpenRecordset(StrSQL) With ScanSet Do Until .EOF .Edit !PhilsPX = !Pxbefore .Update .MoveNext Loop .Close Set ScanSet = Nothing End With End Sub
Phil
Comment