form/subform problem (Access 97)

I have an order entry form based on a query that includes a subform which lists the products ordered. My main form has an autonumber text box to assign the Order ID. My subform is based on a different query but includes an Order ID field. I have linked the two forms with the Order ID fields. (I followed the Orders form and subform in the Northwind database). When I open my form my Order ID field is populated but when I try to go to the subform I get an error message that says "The index/primary key can't contain a null value". As far as I can tell I have followed the Northwind example but cannot figure out why that one works and mine doesn't. Any ideas would be greatly appreciated!

Re: form/subform problem (Access 97)

Is this happening when you create a new record on the mainform, or just moving to the subform from an existing record? Does the info in the subform properly display before moving to it? Do you know if the error is coming from the mainform or subform?

Re: form/subform problem (Access 97)

Thanks Mark for replying so soon. It happens in both instances. When I try to move to the subform (it is on a separate tab) and when I try to move to a new record. I have not been able to enter any info on the subform. I pick a customer and my order number populates (autonumber). I can fill in other information on this tab but when I try to move off of it I get the error message. I tried deleting the tab with the subform and I still get the error message so it must be the main form. Is it possible that the record is not being saved so Access thinks the primary key field is null?

Re: form/subform problem (Access 97)

What is the primary key of the main form?
If this is turning into a real problem, why don't you post the DB and we can take a look for you.
PAt <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Re: form/subform problem (Access 97)

One of the conveniences of working with a bound form is that Access automatically saves the information for you. This occurs when you try to move off the current record (such as moving to a another or new record) or when you move to a subform. If the primarykey is an autonumber field, then this shouldn't be a problem. If it isn't, then you have to make sure you have filled in the data in that field. Alternatively, you might have some code in your form's BeforeUpdate event that is triggering your problems.

Re: form/subform problem (Access 97)

How do you "bind" a form? I've never paid much attention before, but it seems by your comment as if you have a choice of working with a bound or unbound form. How do you set it as bound? Assign a primary key and create a relationship to another table?

Re: form/subform problem (Access 97)

A bound form is one that has a value in its recordsourcce property, either a table or query name or a SQL string. With a bound form, you can also bind controls to fields in the uderlying recordset. If a form doesn't have a recordsource, it is an unbound form and you will have to create code to move between records and populate the individual controls.

Primary keys and relationships are for tables, not forms. Forms are just windows into data.

Re: form/subform problem (Access 97)

Sorry it took so long to reply - was out of the office. My problem apparently was in the code on an AfterUpdate procedure on my Customer Name control. I was trying to populate my ship to name and address after selecting my Customer Name. Once I deleted this I could move to my subform without an error message. Will have to work on the AfterUpdate code. Thanks for your help.