access performing illegal operation (1 Viewer)

A

annedelina

Guest
I have a payroll pgram that I am developing. I have written some code to calculate the toal hours an epmloyee has worked. I want to
check and see if the meployee has worked over 20 and over 40. The code I have wirtten apparently is casing an illegal operation and closing access. Please help. At the bottom of hte message I am sending my code.
this is urgent.
[/begin code]
'Final Paryoll Docuemtnation
'This is the labor file update subform that is giving me problems.
Option Compare Database
Option Explicit
'Dim hours As Integer
'Dim tbHours As Integer

'This is a test to see if i can calculate without causing an illegal page fault.

Private Sub Elaptime_KeyPress(KeyAscii As Integer)
Me.Elaptime = Me.Endtime - Me.Begtime
'hours = Me.Elaptime
'MsgBox (hours)
End Sub

Private Sub Form_AfterUpdate()
On Error GoTo Form_AfterUpdate_Err
DoCmd.GoToRecord , "", acNewRec
Form_AfterUpdate_Exit:
Exit Sub
Form_AfterUpdate_Err:
MsgBox Error$
Resume Form_AfterUpdate_Exit
End Sub


Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err
DoCmd.GoToRecord , "", acNewRec
Form_Open_Exit:
Exit Sub
Form_Open_Err:
MsgBox Error$
Resume Form_Open_Exit
End Sub

Private Sub Date_KeyPress(KeyAscii As Integer)
[Employee Labor Update]![Date].OldValue
End Sub

'this is to see if anything has changed.


'Private Sub Form_Timer()
'Dim fDirty As Boolean
'fDirty = Me.Dirty
'With Me!Elaptime
'If Not (fDirty Eqv .Visible) Then .Visible = fDirty
'End With

'End Sub

'Private Sub Over20_Change()


'This is to see if the employee is working over 20
'Dim over As Integer
'over = tbHours
'over = DSum(Elaptime, "Employee Labor Update Query")
'MsgBox ("Here")
'MsgBox (over)
'If (over > 20) Then
' MsgBox ("Testing to see if >20")
'DoCmd.Beep
'MsgBox ("This Employee is working Over 20.")
' Me.Over20 = Me.tbSumHours - 20
'End If
'End Sub


Private Sub tbSumHours_KeyPress(KeyAscii As Integer)

'MsgBox ("I'm Here.....")
'hours in the last space gives me a runtime error
Dim tbHours As Integer
MsgBox ("This is causing an illegal page fault error.")
tbHours = DSum(Elaptime, "Employee Labor Update Query")
MsgBox (tbHours)
End Sub

[/end code]
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:43
Joined
Feb 19, 2002
Messages
43,223
I did not read the code in detail but I think the problem is with using the KeyPress event. That event traps individual key strokes one at a time and I don't think that is what you want to do. Try moving the code to the BeforeUpdate event for the control instead.
 

Users who are viewing this thread

Top Bottom