Error 3314 can't trap in a form

dimpasa

Registered User.
Local time
Today, 20:28
Joined
Jul 13, 2005
Messages
10
Hi, this a great forum and i'm asking for help :)

1.i trapped error 3314 and other errors at my custm buttons(save,edit...) but...
at my 2 forms(one single and the other continuous, access gives me an error about an empty field in a table (primary id), when i press tab (it moves to next record).
The same action has my continuous form when i click at an empty field at next record or pressing tab with empty values at primary fields.

What can i do to post my own messages?

2. I have a text box (a) that takes value form an other text box (b): b=2*a. both text boxes send values to a table
How can i prevent user from chanching the value on (b) text box?

thanks in advance
Dimitris Greece (sorry for my bad english)
 
1. If you want to trap errors and create your own messages you can this line to the top of the procedure or function:
On Error Goto CatchError

Then you would add this at the bottom:
Code:
ExitSub:
Exit Sub

CatchError:

if err.number = 3314 then
msgbox "error"
else
msgbox err.number & " " & err.description
end if
resume ExitSub
End Sub

However, if your problem is that the computer is not filling in the primary key automatically, you should go to edit the table and change the primary id field to data type "Autonumber". This iwll cause Access to autmatically assign a unique value to each record.

Also, in the form properties, go to the 'other' tab and select Cycle: Current Record. This will cause Access to not leave the current record when you press the tab key.

As for question # 2, I think your asking how do you prevent the user from changing the value? you would set the fields enabled property to false and the locked property to true.
 
1. i already used, as i said, on error statements at my command buttons
ms access gives error when i'm using tab or enter on my form (and have empty primary fields). Where should i reuse on error statement to avoid access messages an show my messages?
I tried on form_BeforeUpdate, form_afterUpdate, form_error with no success.

2. if i lock the text box, it won't take any value, because it value depents on a textbox value!
any help...
 
Because your table has required set to true, I am not sure if you can change the error message generated in this scenario. You might want to change the table so that required is set to false and instead, check for null values in your forms BeforeUpdate event and write your own code to handle the situation.

I am not quite sure what you mean by your second question. How is the value of text box b entered? Is it entered by the user or do you have code to fill the text box? I was under this impression that on field (a) AfterUpdate event you had something like b=2*a and therefore no user input was required on field b. Am I getting this wrong?
 
i'm getting my own messages when an error occurs(empty required field) and clicking my command button (save, nextrecord, ...), but i don't when i use tab or enter to access my records (for the same senario: empty required field)

the (b) textbox takes it value from a code on exit of textbox (a).
I tried your advice but obviously textbox b can't take any value.
I want to lock textbox b, so that a user won't edit the text.

Anyway, thanks
 
You may want to try to set the forms "cycle" property to Current Record. This will prevent access from switching records when you use the tab or enter key and thus will prevent that error from occuring out of your control.

About the text box question, You can edit a text boxes value through code when it is in a locked state and when its enabled property is set to false. It may be possible that your code is flawed in some other way. Exactly, how do you have the control source of field B enetred? After you enter a value in field A when textbox b is locked and disabled, do you get an error message?
 
Also, rather than saving the calculated field B in the database, you may just want to have it calculated each time the user load the screen. FOr example, make field B's control source as follows:

=a*2

The advantage to doing this will be that it will always equal the correct value and you do not need to code anything in fiel a's exit event. Also, it will create a smaller database size because it is always best to store less data than is needed.
 
1. i thought it too, about cycle property, but i didn't like it. it worked yes.

2. unfortunately both text boxes have control sources fields of a table.
 
What I was saying, is rather than have the control source point to a table, why not have the control source simply =2*a. Of coarse, this will only work is B is ALWAYS equal to 2 times a but, if this is the case, there is no point to store field value B in the table.

Also, going back to what I said before, you can have a locked textbox and still asign a value to it.
 
i.m getting errors from access in my continuous form, when i click on previous records,even if cycle property is set to Current Record (if i change the value of a previous record to text and it's datatype is number).
I used onerror statements for that situation too an my save button,on form_error,before update,... but access keeps on erroring!

2. i used your advice about control source. i made a lot of changes because i had a lot of queries, but it's ok
thanks.
any help about first question.
 
Cycle doesn't affect it when you click on records. What errors are you getting when changing records? Error 3314?
 
You are right about no effecting on cycle property.
The error still remains if i give a value on a textbox(datatype as number) as text.
I trapped the error 2113 on my custom save button, but access gives an error like: "the value you entered isn't value for this field", when i press enter or tab(for entering value for the next field in my form)

The disadvantage of cycle to current record is that i have to press my button new record when i have to enter a new record...
Thanks again...
 
Last edited:
Probably the best thing to do is add code to the field's before update event to check if it is numeric. That way, the user can't even exit that field having entered invalid data.

Code:
Private Sub Text0_BeforeUpdate(Cancel As Integer)

If Not (IsNumeric(Text0)) Then
    MsgBox "You must enter a numeric value for this field!"
    Cancel = True
End If

End Sub

Where Text0 is the name of your text box.
 
this is a good idea but unfortunately this doesn't work.
I put a breakpoint at mytext_BeforeUpdate and it doesn't even break at this point.
I did that at form_beforeupdate with the same results.
 
This code runs only when that field has the current focus, and after you have made a change to the value in the field. So, if the value was stored incorrectly to begin with in the database, it will have no effect, but it will prevent a user from storing any new info wrong.
 
Access gives error before geting to mytext_BeforeUpdate sub.
The same happens for other errors too (Error 3201 etc...).
I can trap them only when pressing my buttons.
I don't understand why access is keeping on errors while i have DoCmd.SetWarnings False

It's too hard to make a code for any situation, maybe there is an easiestway
something like DoCmd.SetWarnings False, so that i get rid of access messages at all.
Anyway, jet46 thanks for really fast replies. I owe you a frape! :) (greek coffee)
 

Users who are viewing this thread

Back
Top Bottom