Hi
Having trouble with the following code. On the last record of the file I get an error, because the Exit Do statement doesn't seem to be working. Excuse the code it might not be the most effective way to write it, but the results are good.
Thanks
Dim db As Database
Dim rec As Recordset
Dim soc As String
Dim cnt As Integer
Dim times As Integer
Set db = CurrentDb()
Set rec = db.OpenRecordset("SELECT [Employee Table].[qsoc no],[Employee Table].[qgrouping]" & _
"FROM [Employee Table]" & _
"ORDER BY [Employee Table].[qsoc no]")
cnt = 1
times = 1
soc = " "
Do While Not rec.EOF
Do While times <= 30
' Exit if end of file
If rec.EOF = True Then
Exit Do
End If
' create groupings of 30 records
' if soc no the same as prior record keep in same group
rec.Edit
rec.Fields("qgrouping") = cnt
rec.Update
soc = rec.Fields("qsoc no")
times = times + 1
rec.MoveNext
If rec.Fields("qsoc no") = soc Then
times = times - 1
End If
Loop
' advance to new group of 30
cnt = cnt + 1
times = 1
Loop
rec.Close
Having trouble with the following code. On the last record of the file I get an error, because the Exit Do statement doesn't seem to be working. Excuse the code it might not be the most effective way to write it, but the results are good.
Thanks
Dim db As Database
Dim rec As Recordset
Dim soc As String
Dim cnt As Integer
Dim times As Integer
Set db = CurrentDb()
Set rec = db.OpenRecordset("SELECT [Employee Table].[qsoc no],[Employee Table].[qgrouping]" & _
"FROM [Employee Table]" & _
"ORDER BY [Employee Table].[qsoc no]")
cnt = 1
times = 1
soc = " "
Do While Not rec.EOF
Do While times <= 30
' Exit if end of file
If rec.EOF = True Then
Exit Do
End If
' create groupings of 30 records
' if soc no the same as prior record keep in same group
rec.Edit
rec.Fields("qgrouping") = cnt
rec.Update
soc = rec.Fields("qsoc no")
times = times + 1
rec.MoveNext
If rec.Fields("qsoc no") = soc Then
times = times - 1
End If
Loop
' advance to new group of 30
cnt = cnt + 1
times = 1
Loop
rec.Close