AutoNumber text box on form stopped working

meadows43

Registered User.
Local time
Today, 15:55
Joined
Jan 6, 2003
Messages
54
Hi,

I've got a form with two subforms which was working ok, but now I get a message box popping up that says "Index or Primary key cannot contain a null value." The text box on the form that displays the primary key is the first in the tab order, and I get the error message when I click on any other text box and type. The funny thing is that I do not get the error if I click on one of the combo boxes on the form. If I use the combo box first, the AutoNumber populates in the primary key text box. Also I noticed in the underlying table that the AutoNumbers are being used up, but not assigned to the primary key field or displayed in the form's text box. For example, if I try to add a new record and get the error, there will be a skip in the primary key field if I enter the record in the table directly (which is the only way I can right now).

I noticed that the problem started happening after I changed one of the fields in the first subform from a text box to a combo box. The error message that I mentioned above is always displayed twice in succession (I have to click OK twice).

Any suggestions would be greatly appreciated, because I'm about one step away from getting this thing up and running.

Thanks in advance,
CM
 
My experience has been that Access creates and saves a new autonumber once any of the fields in the new record begin to get edited.

If you're getting an error in this circumstance, my question would be what code and/or validation are you running behind your form, if any. If there really is none, it's hard for me to understand why an autonumber would get generated, deleted, then re-incremented/generated.

Not that this solves your problem, but you should set your tab stop to NO on your autonumber textbox, then lock it so the user can't edit it.

HTH,
John
 
Found the problem. I had some code that was called on the OnCurrent event of one of the subform that incremented one of the fields in the subform. By process of elimination, I moved the code so it executes on the BeforeInsert event instead, and now I do not get the error. Thanks for the advice about locking the autonumber control. I will try to make it a habit.

Thanks,
CM
 

Users who are viewing this thread

Back
Top Bottom