473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

108 100+
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
4 3183
FishVal
2,653 Expert 2GB
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
robtyketto
108 100+
Cheers, thank for the advice.

Will get researching that now !!
Feb 20 '08 #3
robtyketto
108 100+
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
2,653 Expert 2GB
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

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

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
8
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
6
by: sara | last post by:
I have a procedure to automate bringing several Excel files into our Access tables, on a daily basis. The problem is that if the user has a problem, and tries to run the import again (maybe 3...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
2
by: jthep | last post by:
I'm trying to get this piece of code I converted from C to work in C++ but I'm getting an access violation error. Problem occurs at line 61. Someone can help me with this? The function...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.