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

Error handling: Add new records (incomplete record / incorrect data)

100+
P: 108
Greetings,

I added my error checking (see code below) on the Form "On Current" event as
I believe this code will run upon any action on screen being actioned.

Errors happen when users are adding incomplete/incorrect data then pressing
the next navigation button which adds a record if it is the last record.

Where is best to put my error validation?
Thanks Rob


Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3. On Error GoTo MyErr
  4.  
  5. ExtenuatingCount = DCount("[StudentID]", "tblStudentsResultsDelivery", 
  6. "[StudentId]= '" & [txtStudentId] & "' AND [ExtenuatingCircumstances] = 
  7. True")
  8.  
  9. If ExtenuatingCount > 0 Then
  10.     Me.lblExtenuating.Visible = True
  11. Else
  12.     Me.lblExtenuating.Visible = False
  13. End If
  14.  
  15. MyExit:
  16.   Exit Sub
  17.  
  18. MyErr:
  19.     MsgBox "Please check all information is correct and present", 
  20. vbExclamation
  21.     Me.txtStudentId.SetFocus
  22.  
  23. Resume MyExit
  24.  
  25. End Sub 
Feb 20 '08 #1
Share this Question
Share on Google+
4 Replies


FishVal
Expert 2.5K+
P: 2,653
Hi, Rob.

I guess under "error checking" you mean trapping faults (particulary index/constraint violation) when form saves a record into a linked table.
If so, then use Form_Error event to handle the situation.

Regards.
Fish
Feb 20 '08 #2

100+
P: 108
Cheers, thank for the advice.

Will get researching that now !!
Feb 20 '08 #3

100+
P: 108
I put some code in there, but when I try to add records where data is incomplete or junk I get error 2105 (cant move to next record).

My error handling did nothing !

I dont want to write code for every single item on the screen.

Anyone offer any tips or advice?

Copied code below, cheers Rob

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  2.  
  3. On Error GoTo MyErr
  4.  
  5. MyExit:
  6.   Exit Sub
  7.  
  8. MyErr:
  9.     MsgBox "Please check all information is correct and present", vbExclamation
  10.     Me.txtStudentId.SetFocus
  11.  
  12. Resume MyExit
  13.  
  14. End Sub
Feb 20 '08 #4

FishVal
Expert 2.5K+
P: 2,653
I put some code in there, but when I try to add records where data is incomplete or junk I get error 2105 (cant move to next record).

My error handling did nothing !

I dont want to write code for every single item on the screen.

Anyone offer any tips or advice?

Copied code below, cheers Rob

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  2.  
  3. On Error GoTo MyErr
  4.  
  5. MyExit:
  6.   Exit Sub
  7.  
  8. MyErr:
  9.     MsgBox "Please check all information is correct and present", vbExclamation
  10.     Me.txtStudentId.SetFocus
  11.  
  12. Resume MyExit
  13.  
  14. End Sub
Ok.

Lets clarify some things.
  • Once more. Do the changes you make in a record violate linked table rules (indexes, validation rules)?
  • Does the event handler ever run?
  • Do you use form navigation bar to move to a new record or you use custom buttons or whatever other involving VBA code? If so post the code.


.....

Oh, sorry. Didn't pay attention to the code. You just need to realize the difference between On Error statement which allows to handle errors raised by code and Form_Error handler which is fired when form fails to perform some action (e.g. save record). Your code should look like the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  2.     MsgBox "Please check all information is correct and present", vbExclamation
  3.     Me.txtStudentId.SetFocus
  4.     Response = acDataErrContinue  'suppress Access error dialog 
  5. End Sub
Feb 20 '08 #5

Post your reply

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