K
KJGinNC
Hi,
I've got some ugly code below that works, but at the end I get the "Either
BOF or EOF is true...." message. I don't want that message to appear, plus I
can't see why it keeps showing up. I've tried Do..Loop, If..Then..Else,
While..Wend.
Can anyone tell me what's wrong or how to make it better?
Thanks
KJGinNC
Option Compare Database
Private Sub GetRecords_Click()
On Error GoTo Err_GetRecords_Click
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String, strSQL2 As String
Dim Sname As String, Alevel As String
Dim Sweek As Long
Dim flag As Integer
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "Specialist", cnn, adOpenDynamic, adLockPessimistic
rst.MoveFirst
Sname = (rst![MpApprvdBy])
Sweek = [Forms]![Test3]![WeekNum]
Alevel = [Forms]![Test3]![AuditLevel]
DoCmd.SetWarnings False
DoCmd.RunSQL "SELECT TOP 10 PERCENT RawData.ID, RawData.MpApprvdBy,
RawData.Week," _
& "RawData.ToAudit INTO Xtmp FROM RawData WHERE
(((RawData.MpApprvdBy)=" _
& Chr(34) & Sname & Chr(34) & ") AND ((RawData.Week)=" _
& Sweek & ") AND ((RawData.ToAudit) Is Null)) ORDER BY Rnd([ID])"
DoCmd.RunSQL "UPDATE xTmp INNER JOIN RawData ON xTmp.ID = RawData.ID SET
RawData.ToAudit =" _
& Chr(34) & Alevel & Chr(34)
Do While rst.EOF = False
rst.MoveNext
Sname = (rst![MpApprvdBy])
DoCmd.RunSQL "SELECT TOP 10 PERCENT RawData.ID, RawData.MpApprvdBy,
RawData.Week," _
& "RawData.ToAudit INTO Xtmp FROM RawData WHERE
(((RawData.MpApprvdBy)=" _
& Chr(34) & Sname & Chr(34) & ") AND ((RawData.Week)=" _
& Sweek & ") AND ((RawData.ToAudit) Is Null)) ORDER BY Rnd([ID])"
DoCmd.RunSQL "UPDATE xTmp INNER JOIN RawData ON xTmp.ID =
RawData.ID SET RawData.ToAudit =" _
& Chr(34) & Alevel & Chr(34)
Loop
DoCmd.SetWarnings True
Exit_GetRecords_Click:
Exit Sub
Err_GetRecords_Click:
MsgBox Err.Description
Resume Exit_GetRecords_Click
End Sub
I've got some ugly code below that works, but at the end I get the "Either
BOF or EOF is true...." message. I don't want that message to appear, plus I
can't see why it keeps showing up. I've tried Do..Loop, If..Then..Else,
While..Wend.
Can anyone tell me what's wrong or how to make it better?
Thanks
KJGinNC
Option Compare Database
Private Sub GetRecords_Click()
On Error GoTo Err_GetRecords_Click
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String, strSQL2 As String
Dim Sname As String, Alevel As String
Dim Sweek As Long
Dim flag As Integer
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "Specialist", cnn, adOpenDynamic, adLockPessimistic
rst.MoveFirst
Sname = (rst![MpApprvdBy])
Sweek = [Forms]![Test3]![WeekNum]
Alevel = [Forms]![Test3]![AuditLevel]
DoCmd.SetWarnings False
DoCmd.RunSQL "SELECT TOP 10 PERCENT RawData.ID, RawData.MpApprvdBy,
RawData.Week," _
& "RawData.ToAudit INTO Xtmp FROM RawData WHERE
(((RawData.MpApprvdBy)=" _
& Chr(34) & Sname & Chr(34) & ") AND ((RawData.Week)=" _
& Sweek & ") AND ((RawData.ToAudit) Is Null)) ORDER BY Rnd([ID])"
DoCmd.RunSQL "UPDATE xTmp INNER JOIN RawData ON xTmp.ID = RawData.ID SET
RawData.ToAudit =" _
& Chr(34) & Alevel & Chr(34)
Do While rst.EOF = False
rst.MoveNext
Sname = (rst![MpApprvdBy])
DoCmd.RunSQL "SELECT TOP 10 PERCENT RawData.ID, RawData.MpApprvdBy,
RawData.Week," _
& "RawData.ToAudit INTO Xtmp FROM RawData WHERE
(((RawData.MpApprvdBy)=" _
& Chr(34) & Sname & Chr(34) & ") AND ((RawData.Week)=" _
& Sweek & ") AND ((RawData.ToAudit) Is Null)) ORDER BY Rnd([ID])"
DoCmd.RunSQL "UPDATE xTmp INNER JOIN RawData ON xTmp.ID =
RawData.ID SET RawData.ToAudit =" _
& Chr(34) & Alevel & Chr(34)
Loop
DoCmd.SetWarnings True
Exit_GetRecords_Click:
Exit Sub
Err_GetRecords_Click:
MsgBox Err.Description
Resume Exit_GetRecords_Click
End Sub