Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: subfrm autonumber vs non auto link


Message #1 by "Cynthia Halim" <cynltd@y...> on Thu, 31 Oct 2002 11:57:12
Hi All,

I have a prob with my subform. I would like to let my user to select a 
student number from master form (student no is not an autonumber) and then 
when my user click on the subform, it says primary key cannot be null. 
I've checked the parent and child link and they are properly linked with 
the correct fields (student no in master form link with student no in 
subfrm). 

I noticed that when i select a student number from my form (which's 
supposed to be linked with my subfrm) the student no field in my subform 
is null or empty. 

I did a dummy master form with student number as autonumber, when i select 
an autonumber student no, then move to my sub form, the student no field 
in my subform is filled with an autonumber that i selected from my master 
form. Is there a way to get around this problem

ps :I am not sure whether the auto number's the one causing the prob or 
    not!
Thank you very much for your help!! 

regards
cindy  
Message #2 by "Gregory Serrano" <SerranoG@m...> on Thu, 31 Oct 2002 13:19:51
Cindy,

<< I have a prob with my subform. I would like to let my user to select a 
student number from master form (student no is not an autonumber) and then 
when my user click on the subform, it says primary key cannot be null. 
I've checked the parent and child link and they are properly linked with 
the correct fields (student no in master form link with student no in 
subfrm). >>

Because the student number is not the primary key in your main form, and 
it's not used to link tables, it will not be automatically carried into 
the subform's underlying table.  Also, because the autonumber is the 
primary key and not the student number, there really is no need to carry 
student number into the subform at all because the primary key is what 
matters.  It short, don't put the student number in the subform's 
underlying table.  It's the autonumbered primary key that matters.  If you 
do, you're repeating fields in another table and de-normalizing your 
database.

However, if you MUST then you have to put the student number field in the 
subform's underlying table, include it in your subform, make it invisible 
if desired, and then on the subform's "Form AfterUpdate" event, manually 
assign the invisible student number:

   Me.txtStudentNo = Forms.frmMainForm.Form.txtStudentNo

If you're just showing the student number in the subform but not including 
it in its underlying table, then make its textbox unbound and still use 
the above line of code.

Greg

  Return to Index