Gasman
Enthusiastic Amateur
- Local time
- Today, 23:33
- Joined
- Sep 21, 2011
- Messages
- 16,534
Hi all,
I found out today that if a employee gets a commission payment, then so does the manager and another employee
I already have the functionality to add the commission payments per employee, so rather than have to reenter them again, I *thought* I could
Read all payments not yet processed.
Create new records where only the employee ID changes for the manager and the amount also changes for the second employee.
This way when I process the payments, they will all be correctly gathered under each employee?
However my first attempt seemed to create a never ending loop as the records I added became part of the recordset that I was reading for the correct records.? When I started this, there were only six records to process, so I should have added 2 extra records for each of those records, but I stopped at 58
I then googled and discovered dbOpenSnapshot, which I again *thought* would just read the records involved and not grow with my adding new records, but it is still happening.
So how can I go about this, or is there a better method to achieve what I am trying to do please.?
rst is the recordset that I need to read and copy values from
rstComm is the records I need to add.?
TIA
I found out today that if a employee gets a commission payment, then so does the manager and another employee
I already have the functionality to add the commission payments per employee, so rather than have to reenter them again, I *thought* I could
Read all payments not yet processed.
Create new records where only the employee ID changes for the manager and the amount also changes for the second employee.
This way when I process the payments, they will all be correctly gathered under each employee?
However my first attempt seemed to create a never ending loop as the records I added became part of the recordset that I was reading for the correct records.? When I started this, there were only six records to process, so I should have added 2 extra records for each of those records, but I stopped at 58

I then googled and discovered dbOpenSnapshot, which I again *thought* would just read the records involved and not grow with my adding new records, but it is still happening.

So how can I go about this, or is there a better method to achieve what I am trying to do please.?
rst is the recordset that I need to read and copy values from
rstComm is the records I need to add.?
TIA
Code:
Private Sub cmdJCCommission_Click()
On Error GoTo ErrHandler
Dim db As Database
Dim rst As Recordset, rstComm As Recordset
Dim strSQL As String
Set db = CurrentDb()
strSQL = " SELECT tblCommission.CommissionDate, tblCommission.Reason, tblCommission.Amount, tblEmployee_1.EmployeeID, tblCommission.Processed"
strSQL = strSQL & " FROM tblEmployee AS tblEmployee_1 INNER JOIN (tblCommission INNER JOIN tblEmployee ON tblCommission.EmployeeID = tblEmployee.EmployeeID) ON tblEmployee_1.EmployeeID = tblEmployee.ReportsTo"
strSQL = strSQL & " WHERE (((tblEmployee_1.EmployeeID)=15) AND ((tblCommission.Processed) Is Null))"
' Open recordsets ready
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
Set rstComm = db.OpenRecordset("tblCommission", dbOpenTable)
SetStatusBar ("Adding Commissions ....")
If rst.EOF Then
MsgBox "No commission records found, check processed date"
GoTo ExitSub
Else
rst.MoveFirst
Do While Not rst.EOF
' First JC commission as values are same
rstComm.AddNew
rstComm!EmployeeID = 15
rstComm!CommissionDate = rst!CommissionDate
rstComm!Reason = rst!Reason
rstComm!Amount = rst!Amount
rstComm.Update
' Now Adam Lewis commission
rstComm.AddNew
rstComm!EmployeeID = 18
rstComm!CommissionDate = rst!CommissionDate
rstComm!Reason = rst!Reason
rstComm!Amount = 1
rstComm.Update
rst.MoveNext
Loop
End If
SetStatusBar ("Commissions created")
rstComm.Close
rst.close
ExitSub:
Set rstComm = Nothing
Set rst = Nothing
Set db = Nothing
Err_Exit:
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Number & " " & Err.Description
Resume ExitSub