I'm not really experienced with the advanced functions in Access. I'm using Access 97 to create a database that will create and track work orders through various queues- ie maintenance, accounting etc. At the end of the process the work order is 'complete' and can eventually be archived.
The problem I'm having is that to be able to have some functionality for security I've created a subform with a one to one relationship with the main form. I realize that this flies in the face of convention, but I needed to limit access to the accounting table and this was the only way I could think of to make that happen. I've violated another rule by trying to retain a calculated amount in a table field. I have to maintain this because one element in calculation may change with time- the curRate. This is the current labor rate being coded out for any maintenance work completed. It changes one or maybe twice per year so I need to lock in the total offset for the work order charge.
I want the labor charge portion of the account coding to happen automatically so I've set up the following code in the onCurrent event in the subform. As some additional information this first line of account coding may be different depending on the type of workorder. There can be up to 6 lines of coding for each workorder. If I can get this to work I may have another 2 or three lines of account coding happen automatically to reduce the amount of manual keying occuring in Accounting
Private Sub Form_Current()
'Sets up the first line of code as the total offset for the workorder
Dim lngHours As Long
Dim curRate As Currency
Dim curAmt As Currency
lngHours = Forms![frmAccountingWorkorders]![Fab_Workorders]![TotalHours]
curRate = Forms![frmAccountingWorkorders]![LaborRate]
curAmt = lngHours * curRate
If Forms![frmAccountingWorkorders]![WoType] = 1 Then
Forms![frmAccountingWorkorders]![frmAccountCoding]![Loc1] = 23
Forms![frmAccountingWorkorders]![frmAccountCoding]![DeptChrg1] = 0
Forms![frmAccountingWorkorders]![frmAccountCoding]![Prod1] = 3000
Forms![frmAccountingWorkorders]![frmAccountCoding]![Account1] = 110203
Forms![frmAccountingWorkorders]![frmAccountCoding]![Amount1] = curAmt * -1
Else
Forms![frmAccountingWorkorders]![frmAccountCoding]![Loc1] = 23
Forms![frmAccountingWorkorders]![frmAccountCoding]![DeptChrg1] = 0
Forms![frmAccountingWorkorders]![frmAccountCoding]![Prod1] = 3000
Forms![frmAccountingWorkorders]![frmAccountCoding]![Account1] = 7900501
Forms![frmAccountingWorkorders]![frmAccountCoding]![Amount1] = curAmt * -1
End If
End Sub
This code works great if I only move forward through the records and fully code them at the time I am reviewing them. If I try to backup and look at a previous workorder I get an error message: 'The changes you requested were not successful because they would create duplicate values in the index, primary key, or relationship etc' Since it is often the case that one or more work orders needs to be passed over for coding later I need some way to prevent this error from happening.
I'm hoping someone can help me - Thanks!
The problem I'm having is that to be able to have some functionality for security I've created a subform with a one to one relationship with the main form. I realize that this flies in the face of convention, but I needed to limit access to the accounting table and this was the only way I could think of to make that happen. I've violated another rule by trying to retain a calculated amount in a table field. I have to maintain this because one element in calculation may change with time- the curRate. This is the current labor rate being coded out for any maintenance work completed. It changes one or maybe twice per year so I need to lock in the total offset for the work order charge.
I want the labor charge portion of the account coding to happen automatically so I've set up the following code in the onCurrent event in the subform. As some additional information this first line of account coding may be different depending on the type of workorder. There can be up to 6 lines of coding for each workorder. If I can get this to work I may have another 2 or three lines of account coding happen automatically to reduce the amount of manual keying occuring in Accounting
Private Sub Form_Current()
'Sets up the first line of code as the total offset for the workorder
Dim lngHours As Long
Dim curRate As Currency
Dim curAmt As Currency
lngHours = Forms![frmAccountingWorkorders]![Fab_Workorders]![TotalHours]
curRate = Forms![frmAccountingWorkorders]![LaborRate]
curAmt = lngHours * curRate
If Forms![frmAccountingWorkorders]![WoType] = 1 Then
Forms![frmAccountingWorkorders]![frmAccountCoding]![Loc1] = 23
Forms![frmAccountingWorkorders]![frmAccountCoding]![DeptChrg1] = 0
Forms![frmAccountingWorkorders]![frmAccountCoding]![Prod1] = 3000
Forms![frmAccountingWorkorders]![frmAccountCoding]![Account1] = 110203
Forms![frmAccountingWorkorders]![frmAccountCoding]![Amount1] = curAmt * -1
Else
Forms![frmAccountingWorkorders]![frmAccountCoding]![Loc1] = 23
Forms![frmAccountingWorkorders]![frmAccountCoding]![DeptChrg1] = 0
Forms![frmAccountingWorkorders]![frmAccountCoding]![Prod1] = 3000
Forms![frmAccountingWorkorders]![frmAccountCoding]![Account1] = 7900501
Forms![frmAccountingWorkorders]![frmAccountCoding]![Amount1] = curAmt * -1
End If
End Sub
This code works great if I only move forward through the records and fully code them at the time I am reviewing them. If I try to backup and look at a previous workorder I get an error message: 'The changes you requested were not successful because they would create duplicate values in the index, primary key, or relationship etc' Since it is often the case that one or more work orders needs to be passed over for coding later I need some way to prevent this error from happening.
I'm hoping someone can help me - Thanks!