By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,398 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,398 IT Pros & Developers. It's quick & easy.

Error trouble

P: 6
Hi, everyone.

I'm currently working on a task, and I'm not sure how to do it. The user gets an error message upon entering a student's attendance for a class. The error happens randomly, and after several attempts, it works. There is an error trapping in the save attendance status control that points to the “.update” code that triggers the error.

My job is to determine what part of the “.update” action fails. Do you have any ideas of how to approach this? Any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSubmitAttend_Click()
  2. 'On Error GoTo eh
  3. Dim lErrorTrap As Integer
  4.     If Me.shpSaveChanges.Visible = False Or
  5.  IsNull(Me.lstDayAttendRecord) Or Me.lstDayAttendRecord = 0 Then
  6.         Exit Sub
  7.     End If
  8.     Dim rs As ADODB.Recordset
  9.     Set rs = New ADODB.Recordset
  10.         With rs
  11.             .ActiveConnection = CurrentProject.Connection
  12.             .CursorType = adOpenKeyset
  13.             .LockType = adLockOptimistic
  14. lErrorTrap = 1
  15.             .Open "Select * FROM tblAttendanceHistory WHERE
  16.  AttendanceHistoryId = " & Me.lstDayAttendRecord
  17. lErrorTrap = 2
  18.                 rs!AttendanceStatusID = Me.cboAttendanceStatusId
  19. lErrorTrap = 3
  20.                 rs!MinutesAttended = Me.txtMinutesAttended
  21. lErrorTrap = 4
  22.                 rs!AttendanceComments = Me.txtAttendanceComments
  23. lErrorTrap = 5
  24.                 rs!ClassNumber = lClassNumber
  25. lErrorTrap = 6
  26.             .Update
  27. lErrorTrap = 7
  28.         End With
  29.     RefreshDayAttendList
  30.     ClearBlueChange
  31. lErrorTrap = 8
  32.     Me.cboAttendanceStatusId = 0
  33.     Me.txtMinutesAttended = 0
  34. lErrorTrap = 9
  35.     Me.txtAttendPartName = ""
  36.     Me.txtAttendanceComments = ""
  37. lErrorTrap = 10
  38.     Me.lstDayAttendRecord = 0
  39.     Me.lstDayAttendRecord.SetFocus
  40. lErrorTrap = 11
  41. ex:
  42.     Set rs = Nothing
  43.     Exit Sub
  44. eh:
  45.     ehGeneralOpError Form.Name, "cmdSubmitAttend_Click", lErrorTrap
  46.     GoTo ex
  47. End Sub
  48.  

Regards,
Sep 6 '07 #1
Share this Question
Share on Google+
4 Replies


Scott Price
Expert 100+
P: 1,384
In line 24 of your code your are pointing to an un-initialized variable (at least one that isn't dim'ed in this section of code...) Make sure you have Option Explicit set in the top of your module window just below Option Compare Database...

Regards,
Scott
Sep 8 '07 #2

ADezii
Expert 5K+
P: 8,669
Hi, everyone.

I'm currently working on a task, and I'm not sure how to do it. The user gets an error message upon entering a student's attendance for a class. The error happens randomly, and after several attempts, it works. There is an error trapping in the save attendance status control that points to the “.update” code that triggers the error.

My job is to determine what part of the “.update” action fails. Do you have any ideas of how to approach this? Any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSubmitAttend_Click()
  2. 'On Error GoTo eh
  3. Dim lErrorTrap As Integer
  4.     If Me.shpSaveChanges.Visible = False Or
  5.  IsNull(Me.lstDayAttendRecord) Or Me.lstDayAttendRecord = 0 Then
  6.         Exit Sub
  7.     End If
  8.     Dim rs As ADODB.Recordset
  9.     Set rs = New ADODB.Recordset
  10.         With rs
  11.             .ActiveConnection = CurrentProject.Connection
  12.             .CursorType = adOpenKeyset
  13.             .LockType = adLockOptimistic
  14. lErrorTrap = 1
  15.             .Open "Select * FROM tblAttendanceHistory WHERE
  16.  AttendanceHistoryId = " & Me.lstDayAttendRecord
  17. lErrorTrap = 2
  18.                 rs!AttendanceStatusID = Me.cboAttendanceStatusId
  19. lErrorTrap = 3
  20.                 rs!MinutesAttended = Me.txtMinutesAttended
  21. lErrorTrap = 4
  22.                 rs!AttendanceComments = Me.txtAttendanceComments
  23. lErrorTrap = 5
  24.                 rs!ClassNumber = lClassNumber
  25. lErrorTrap = 6
  26.             .Update
  27. lErrorTrap = 7
  28.         End With
  29.     RefreshDayAttendList
  30.     ClearBlueChange
  31. lErrorTrap = 8
  32.     Me.cboAttendanceStatusId = 0
  33.     Me.txtMinutesAttended = 0
  34. lErrorTrap = 9
  35.     Me.txtAttendPartName = ""
  36.     Me.txtAttendanceComments = ""
  37. lErrorTrap = 10
  38.     Me.lstDayAttendRecord = 0
  39.     Me.lstDayAttendRecord.SetFocus
  40. lErrorTrap = 11
  41. ex:
  42.     Set rs = Nothing
  43.     Exit Sub
  44. eh:
  45.     ehGeneralOpError Form.Name, "cmdSubmitAttend_Click", lErrorTrap
  46.     GoTo ex
  47. End Sub
  48.  

Regards,
Off the top of my head:
  1. In Line #44, code execution will never reach Label ex: since On Error GoTo eh is remmed out. Error handler will be totally ineffective.
  2. In Line #42, you have set the Object Variable to Nothing (rs) and released Resources assigned to it, but you never closed the Recordset beforehand (rs.Close).
  3. In Line #24, what does lClassNumber refer to and where is it declared. Right now it's simply an uninitialized Variable.
  4. While opening the Recordset (rs) in Line #15, what happens if Me.lstDayAttendRecord is Null?
  5. Do the Arguments in the Error Handler call (ehGeneralOpError) coincide with their Declarations in the actual Procedure ehGeneralOPError(String, String, Integer)?
Sep 8 '07 #3

P: 19
Hi, everyone.

I'm currently working on a task, and I'm not sure how to do it. The user gets an error message upon entering a student's attendance for a class. The error happens randomly, and after several attempts, it works. There is an error trapping in the save attendance status control that points to the “.update” code that triggers the error.

My job is to determine what part of the “.update” action fails. Do you have any ideas of how to approach this? Any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSubmitAttend_Click()
  2. 'On Error GoTo eh
  3. Dim lErrorTrap As Integer
  4.     If Me.shpSaveChanges.Visible = False Or
  5.  IsNull(Me.lstDayAttendRecord) Or Me.lstDayAttendRecord = 0 Then
  6.         Exit Sub
  7.     End If
  8.     Dim rs As ADODB.Recordset
  9.     Set rs = New ADODB.Recordset
  10.         With rs
  11.             .ActiveConnection = CurrentProject.Connection
  12.             .CursorType = adOpenKeyset
  13.             .LockType = adLockOptimistic
  14. lErrorTrap = 1
  15.             .Open "Select * FROM tblAttendanceHistory WHERE
  16.  AttendanceHistoryId = " & Me.lstDayAttendRecord
  17. lErrorTrap = 2
  18.                 rs!AttendanceStatusID = Me.cboAttendanceStatusId
  19. lErrorTrap = 3
  20.                 rs!MinutesAttended = Me.txtMinutesAttended
  21. lErrorTrap = 4
  22.                 rs!AttendanceComments = Me.txtAttendanceComments
  23. lErrorTrap = 5
  24.                 rs!ClassNumber = lClassNumber
  25. lErrorTrap = 6
  26.             .Update
  27. lErrorTrap = 7
  28.         End With
  29.     RefreshDayAttendList
  30.     ClearBlueChange
  31. lErrorTrap = 8
  32.     Me.cboAttendanceStatusId = 0
  33.     Me.txtMinutesAttended = 0
  34. lErrorTrap = 9
  35.     Me.txtAttendPartName = ""
  36.     Me.txtAttendanceComments = ""
  37. lErrorTrap = 10
  38.     Me.lstDayAttendRecord = 0
  39.     Me.lstDayAttendRecord.SetFocus
  40. lErrorTrap = 11
  41. ex:
  42.     Set rs = Nothing
  43.     Exit Sub
  44. eh:
  45.     ehGeneralOpError Form.Name, "cmdSubmitAttend_Click", lErrorTrap
  46.     GoTo ex
  47. End Sub
  48.  

Regards,
hi..am also doing same,if u have correct code,can u please share me this..please reply me..its very urgent..thanks in advance..
Oct 15 '07 #4

Scott Price
Expert 100+
P: 1,384
Yashumrshn,

You have asked your question in another member's thread. This is called thread hijacking and is not allowed on this site. There are various reasons for this, the principal of which is that it typically diverts the flow of the thread away from his needs and into yours. Another is that it will tend to mean that your new question is not seen as such, and may get overlooked by many of our experts (You appreciate that they're not looking for answered questions).
Please post your questions in their own threads in future (See POSTING GUIDELINES).

Especially pay attention to the section about How to Ask a Question, as your question is poorly worded and doesn't provide enough information for us to help you.

MODERATOR.
Oct 15 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.