Thought I'd give you an update on my eventual conclusion.
I used a WEND and SELECT TOP with flags.
First some more background - at work we have a requirement to transfer large amounts of lookups from one system to another. As part of the transfer many of those lookups need to be shortened as the destination fields only accept 6 characters. Clearly the best method will be to create translation tables or converstion tables listing the old and new values and then include then join the table in an update query to update the values.
I am working on this project with others and it may be difficult for us to coordinate a link to a database that will allow everyone to join in the correct conversion tables. I was therefore thinking about nested IF queries that could be distributed to individual developers. Some may be aware but in Access there is a limit on how many nested IFs Access will accept before complaining that statements are too complicated if you go over this limit. From my testing I believe this to be 13 in MS Access 2003.
So I thought if I could generate multiple nested IF statements none larger than 13.
I set it up with a WEND loop and a select top statement with three flag fields in three recordsets. The structure of a nested IF statement is such that I I appear to need three recordsets. One that manages the loop through of the oldvalues at the start of the IF statement, one to manage the closing brackets after the string construction of old values and then a further recordset to manage the construction of the tail end of the IF statement.
I really only wanted one flag field that as per the previous discussion allows re-querying of the top 13 records. Interestingly things got a bit weird when I only used one flag field. It appears that while I was setting the recordsets at the beginning of the statement as I went through there was some kind of dynamic link between the recordsets such that as I flagged up completion through the loop with a 1 this was altering the subsequent recordsets such that my recordsets were getting out of sync. (My IF statement uses a where clause to select only those records to be updated in the front of the statement as such the front and back of the SQL statement that is pulling from two different recordsets need to match such that an if statement for an old value is matched with a where statement of the same old value). It was as if the recordsets rather than being set at the beginning of the VBA were themselves a query on the table that as it was altered by the first recordset altered the subsequent recordset. This lead to a mismatch of the IF front part to the where back part.
I also had issues with rs.recordcount which I needed in order to create the commas between the IIF statements and the ORs in the second half of my SQL. I had to use rs.MoveLast before each recordset.recordcount to ensure that recordcount was correct as omission of movelast resulted in a record count of 0 on first pass. Thus I used rs.MoveLast then rs.recordcount I then had to reset the recordsets to movefirst otherwise the recordsets loop would immediately exit.
I also used the WEND statement to loop through an arbitrary number of times. My code definitely has room for improvement - I'm sure that there must be a way of only using one flag field to make it work and I feel I probably am using more recordsets than are strictly necessary. Additionally I have set the loop on the wend statement subjectively at 200 there is room to dynamically set this figure by measuring the count in the conversion table and then dividing that number by the number you have set the query at - in this case 13. As it stands. Conversion tables with a record count beyond 200 * 13 would have those records above this number un-translated. That's not an issue for me as I don't have quite that many nested If statements to make.
Out of interest I tried a for next loop as well but didn't seem to like that.
After all that probably will use a table anyway
