473,325 Members | 2,771 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,325 software developers and data experts.

about error 3314 (null value)

mseo
181 100+
hi,
I am develping a form for adding employees
I set the controls for firstname, middlename, lastname,hiredate (Is Not Null) in the table.
but in the form when I don't insert any field of those fields I definetly will get error number 3314 because I didn't insert the required fields
so I just want to write my custom message when I click save to be viewed for the user or at least when the user doesn't insert the required field
I used this code but it doesn't work as I want

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  2. if an error occurs because of missing data in a required field
  3. 'display our own custom error message
  4.          Const conErrRequiredData = 3314
  5.    If DataErr = conErrRequiredData Then
  6.         MsgBox ("Please ensure that you enter a First Name , Last Name , Middle Name and Hire Date ")
  7.         Response = acDataErrContinue
  8.    Else
  9.     'Display a standard error message
  10.        Response = acDataErrDisplay
  11.    End If
  12. End Sub
  13.  
please help me handling this error
thanks in advance for any help you may provide me
Oct 31 '09 #1
7 13005
ADezii
8,834 Expert 8TB
@mseo
A better, and more personalized, approach may be to check for these conditions in the BeforeUpdate() Event of the Form, as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me![firstname]) Then
  3.   MsgBox "You must enter a First Name before this Record can be saved"
  4.     Cancel = True: Me![firstname].SetFocus
  5. ElseIf IsNull(Me![middlename]) Then
  6.   MsgBox "You must enter a Middle Name before this Record can be saved"
  7.     Cancel = True: Me![middlename].SetFocus
  8. ElseIf IsNull(Me![lastname]) Then
  9.   MsgBox "You must enter a Last Name before this Record can be saved"
  10.     Cancel = True: Me![lastname].SetFocus
  11. ElseIf IsNull(Me![hiredate]) Then
  12.   MsgBox "You must enter a Hire Date before this Record can be saved"
  13.     Cancel = True: Me![hiredate].SetFocus
  14. End If
  15. End Sub
Oct 31 '09 #2
missinglinq
3,532 Expert 2GB
I agree with ADezii; you really have much more control doing this kind of validation in the Form_BeforeUpdate event.

Also, please remember, when posting code, to use code tags, as it makes it much easier for those trying to help you to read it. It's really easy to do.
  1. Click on "Go Advanced"
  2. Hilight your code
  3. Click on the pound sign (#) in the tool bar
Linq ;0)>
Oct 31 '09 #3
mh90
3
Hi, I've applied the solution which is great, but I get a "No Record" error. Is there something I can do about that?

Thanks for any help!
Jun 2 '10 #4
missinglinq
3,532 Expert 2GB
This is very strange! Where did place your code? If it's in the Form_Before event, as ADezii's example shows, there really has to be a record! Otherwise Access wouldn't go to the Form_BeforeUpdate event.

Linq ;0)>
Jun 2 '10 #5
mh90
3
Whoops, I guess the preview button is there for a reason!

I meant to say, it returns a "No current record" error.

I did put it in the Form_BeforeUpdate. However, my scenario is that the user is entering a completely new record (the form always opens in Add Mode there are no navigation tools to see previous records). Does that have anything to do with the error?
Jun 2 '10 #6
ADezii
8,834 Expert 8TB
@mh90
Should have nothing to do with the Error at all. Is there other code running in this Event or in the Current() Event of the Form?
Jun 2 '10 #7
mh90
3
Nope, there are no other codes.

I've narrowed it down to this. If I remove the lines that have "Cancel = True: Me![firstname].SetFocus"
Then the "No current record" error goes away. But the original "The field "Customer.CompanyName" cannot contain a Null Value etc." comes back after one clicks ok on the customized message.
Jun 2 '10 #8

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

Similar topics

3
by: WindAndWaves | last post by:
I am writing error handling procedures at the moment. Here are some questions: 1. Can you write a procedure that picks up any error and deals with it no matter where it happens in the database?...
2
by: Bill Stock | last post by:
I have a subform which is causing a 3314 (Field can't contain a null value because required is set to True) error. I solved this problem by trapping it in the before update event. But then I...
1
by: Jeremy Ames | last post by:
I have a datagrid that updates the table using a stored procedure. The stored procedure is confirmed to complete correctly, yet the sql data adapter is returning an error that my application is...
7
by: Adrian Parker | last post by:
'function to convert null to nothing Function CheckDate(ByVal DRow As DataRow, ByVal strCol As String) As Date If DRow.Item(strCol) Is System.DBNull.Value Then Return Nothing Else Return...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
11
by: hammad.awan_nospam | last post by:
Hello, I'm wondering if it's possible to do the following with Generics: Let's say I have a generic member variable as part of a generic class like this: List<DLinqQuery<TDataContext>>...
4
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and...
5
by: bkberg05 | last post by:
Hi - I have a combo box field on a form. The field is required (can't be left blank). Occassionally a user will come to the field and the combo box will not contain the desired record. So I added...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.