Connecting Tech Pros Worldwide Forums | Help | Site Map

me.refresh causes 'field cannot contain Null value' error

Member
 
Join Date: Aug 2009
Posts: 43
#1: Sep 2 '09
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 a button that takes the user to a place where they can add a record and all its associated information. Then once the user closes that form and goes back to the combo box, of course the new record isn't in there. So I added a me.refresh to the GotFocus event. Seemed obvious and I've used this before with success. But now whenever I enter the field, I get a Run-time error '3314' with the label: "The field 'Order.Vendor_ID' cannot contain a Null value because the Required property for this field is set to True. Enter a value in this field."

I've tried using me.requery also (don't really know the difference), but I get the same result. I've tried adding a me.required = false before the me.refresh and then putting the me.required = true back on. It wouldn't let me do that.

I'm not sure what else to try.

Any help you can provide would be greatly appreciated.

Thanks
Bill

Member
 
Join Date: Mar 2009
Location: Conroe, TX
Posts: 57
#2: Sep 2 '09

re: me.refresh causes 'field cannot contain Null value' error


Is the combobox bound. If it is then when they start typing their info into the box it would be making the record "dirty". If the record is dirty, then they remove the information, then it would be interpreted as an empty value. The me.refresh is causing a save (somebody is gonna talk bad about me for using the word save) and now the record is dirty and the field is empty. Is this the same box as your other question?

Afterupdate of the combobox could be
Expand|Select|Wrap|Line Numbers
  1. If Me.Dirty Then
  2.     if me.combobox = "" then
  3.         me.undo
  4.     end if
  5. end if 
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#3: Sep 2 '09

re: me.refresh causes 'field cannot contain Null value' error


I would say it is Combobox control that needs to be required, not form.
Member
 
Join Date: Aug 2009
Posts: 43
#4: Sep 2 '09

re: me.refresh causes 'field cannot contain Null value' error


Interesting. But no luck as yet.

I added the code above in the Afterupdate (substituting vendor_id which is the name of the combobox for the word combobox above). The me.refresh is in the Gotfocus event.

Now I get the same error the first time I enter the field.

And yes, it's the same field as the other post.
Member
 
Join Date: Aug 2009
Posts: 43
#5: Sep 2 '09

re: me.refresh causes 'field cannot contain Null value' error


Hi FishVal - I'm sorry but I don't understand. If the me.refresh is causing a save of the record and that's not allowed when the field is required and that's why i'm getting the error, then i'd like to turn off the required value, do the refresh and then turn the required back on.

I tried vendor_id.required = false (vendor_id is name of combobox), but that didn't work.
Member
 
Join Date: Aug 2009
Posts: 43
#6: Sep 2 '09

re: me.refresh causes 'field cannot contain Null value' error


Never mind everyone and thanks for trying to help.

me.refresh was wrong

combobox_name.requery was right

refresh causes record to commit and validation rules caused error

requery doesn't cause a recommit and doesn't create the error.

still having the problem that's mentioned in my other post of typing a few characters, then backing up over them and then trying to leave the field and getting the validation error.
Reply