G
Guest
Hi,
I am getting back into Access development and programming and of course I'm
in over my head with no one to turn to.
I'm creating a database in Access2000 to track an audting function. The
data will be imported from an outside database on a weekly basis. Then the
data must be randomly sampled per Approval Name ie 10% of each person's
claims per week must be reviewed. I've managed to write the queries to find
the sample per person and to flag them for auditing, but it does each person
one at a time. I have a form that does that quite nicely. It takes
information from the RawData table, groups based on fields, assigns random
numbers and selects the 10% and makes a table Xtmp. The second query takes
the information in the Xtmp table and updates the corresponding record in
the RawData table.
BUT I've been struggling with writing something that will do it for all
Specialists at once. I've tried writing an Event Procedure that will use the
MpApprvdBy name in the Specialist table to run the queries as SQL until all
people have been updated, but it gives me the generic error of "object
variable or with block variable not set". I've searched and searched and
don't know what silly stupid simple thing I'm doing wrong... or perhaps my
entire logic is flawed. I've hard coded some variables trying to get it to
work and that didn't make a difference.
Table
Below is my code! I appreciate any help!
Thanks
KJGinNC
Option Compare Database
Option Explicit
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String, strSQL2 As String, SpecName As String
Set cnn = CurrentProject.Connection
strSQL = "SELECT TOP 10 PERCENT RawData.ID, RawData.MpApprvdBy,
RawData.MpSrNum, RawData.Week" _
& "INTO xTmp FROM RawData" _
& "GROUP BY RawData.ID, RawData.MpApprvdBy, RawData.MpSrNum,
RawData.Week, RawData.ToAudit" _
& "HAVING (((RawData.MpApprvdBy) = [SpecName]) And ((RawData.Week) =
'22') And ((RawData.ToAudit) Is Null))" _
& "ORDER BY Rnd([ID])"
strSQL2 = "UPDATE xTmp INNER JOIN RawData ON xTmp.ID = RawData.ID SET
RawData.ToAudit = '1'"
rst.Open "Specialist", cnn, adOpenDynamic, adLockPessimistic
rst.MoveFirst
Do
SpecName = (rst![MpApprvdBy])
cnn.Execute strSQL
cnn.Execute strSQL2
rst.MoveNext
Loop Until rst.EOF
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
I am getting back into Access development and programming and of course I'm
in over my head with no one to turn to.
I'm creating a database in Access2000 to track an audting function. The
data will be imported from an outside database on a weekly basis. Then the
data must be randomly sampled per Approval Name ie 10% of each person's
claims per week must be reviewed. I've managed to write the queries to find
the sample per person and to flag them for auditing, but it does each person
one at a time. I have a form that does that quite nicely. It takes
information from the RawData table, groups based on fields, assigns random
numbers and selects the 10% and makes a table Xtmp. The second query takes
the information in the Xtmp table and updates the corresponding record in
the RawData table.
BUT I've been struggling with writing something that will do it for all
Specialists at once. I've tried writing an Event Procedure that will use the
MpApprvdBy name in the Specialist table to run the queries as SQL until all
people have been updated, but it gives me the generic error of "object
variable or with block variable not set". I've searched and searched and
don't know what silly stupid simple thing I'm doing wrong... or perhaps my
entire logic is flawed. I've hard coded some variables trying to get it to
work and that didn't make a difference.
Table
Below is my code! I appreciate any help!
Thanks
KJGinNC
Option Compare Database
Option Explicit
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String, strSQL2 As String, SpecName As String
Set cnn = CurrentProject.Connection
strSQL = "SELECT TOP 10 PERCENT RawData.ID, RawData.MpApprvdBy,
RawData.MpSrNum, RawData.Week" _
& "INTO xTmp FROM RawData" _
& "GROUP BY RawData.ID, RawData.MpApprvdBy, RawData.MpSrNum,
RawData.Week, RawData.ToAudit" _
& "HAVING (((RawData.MpApprvdBy) = [SpecName]) And ((RawData.Week) =
'22') And ((RawData.ToAudit) Is Null))" _
& "ORDER BY Rnd([ID])"
strSQL2 = "UPDATE xTmp INNER JOIN RawData ON xTmp.ID = RawData.ID SET
RawData.ToAudit = '1'"
rst.Open "Specialist", cnn, adOpenDynamic, adLockPessimistic
rst.MoveFirst
Do
SpecName = (rst![MpApprvdBy])
cnn.Execute strSQL
cnn.Execute strSQL2
rst.MoveNext
Loop Until rst.EOF
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub