Thanks Dave,
I retyped them as
Dim dbs As Database
Dim rst As Recordset
Dim RanValue, noLoop, nolooped, AccNoOfRecords, RanNum, ln As Integer
Dim sqlStr, NoOfRecords As String
Dim RecordArray As Variant
But with no joy.
I think the problem is that it's reading NoOfRecords as...