Results 1 to 5 of 5
  1. #1
    getmemoney is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    2

    Index or Primary Key cannot contain a null value


    I'm facing this issue when I run into a next record of sub Form. I created a form/subform manually (w/o Form wizard) by created 2 forms separately, then I dragged the Child Form into Main Form like a subform by subform/subreport wizard. I don't know if I got a mistake at this step or not. I believe that the error came from SubForm because the main form still writes a record even when I got the error message before I go to the next record of subform, and stuck there.
    I also try to trace to the error by pressing Ctrl+Break when the error message pop-up but nothing happens.
    My main form is: FormHoaDon, Subform is CTHoaDonSubF
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    A subform RecordSource should not include the table the main form is bound to. Also, cannot use one form to enter data into multiple tables. Split up the subform to multiple subforms.

    A textbox on subform references a field on main form that isn't on the main form.

    Why have a textbox on subform reference MaHoaDon field of main form?

    GiaNULibo fieldname used in expression but that field doesn't exist.
    Last edited by June7; 01-10-2013 at 02:01 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    In addition to June7's comments, once you've created your basic Main Form and created a Form to base your Subform on, use the Subform Wizard! It will do the heavy lifting for you, such as setting the Link Master Fields/Link Child Fields Properties, so that the Subform Records change, appropriately, as the Main Form Record changes. If the Wizard doesn't automatically set these Properties, it may mean that you don't actually have matching Fields in both Forms, a hint that you have something wrong in the relationship between the two. It may even mean that there is no relationship between the two, which is what a Main Form/Subform scenario is all about.

    Linq ;0)>

  4. #4
    getmemoney is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    2
    Quote Originally Posted by June7 View Post
    A subform RecordSource should not include the table the main form is bound to. Also, cannot use one form to enter data into multiple tables. Split up the subform to multiple subforms.

    A textbox on subform references a field on main form that isn't on the main form.

    Why have a textbox on subform reference MaHoaDon field of main form?

    GiaNULibo fieldname used in expression but that field doesn't exist.
    Quote Originally Posted by Missinglinq View Post
    In addition to June7's comments, once you've created your basic Main Form and created a Form to base your Subform on, use the Subform Wizard! It will do the heavy lifting for you, such as setting the Link Master Fields/Link Child Fields Properties, so that the Subform Records change, appropriately, as the Main Form Record changes. If the Wizard doesn't automatically set these Properties, it may mean that you don't actually have matching Fields in both Forms, a hint that you have something wrong in the relationship between the two. It may even mean that there is no relationship between the two, which is what a Main Form/Subform scenario is all about.

    Linq ;0)>
    Thanks so much for your replies, I've tried so many times since you guys replied me but it seems like I did not actually know how the Access works when it get data from my form and write it to my tables.
    I also tried to use Form Wizard but I don't know should I show the fields of intermediate tables (tables for many-to-many relationship) in my form or not because I always recieve the message "The Microsoft Access Database engine cannot find a record in the table "NuocUong" with key matching field(s) "CTHoaDon_MaNUong"" when I show up all thef fields of tables that relates to my form.

    I just want to create a simple form to enter my customer's bill which is include a main form with Date and IDBill (IDHoaDon) and a subform (CTHoaDonSubF) which is include a category of our drinks (Combo box 1 - TenLoaiNU), our drinks name (cascade combo box depends on Combo box 1 - TenNUong), a drinks' price textbox or listbox (depends on the 2nd combo box - GiaNU), discount textbox (enter manually, default value is 0% - ChietKhau), amount of drinks textbox (Enter manually, default value is 1 - SoLuong) and a calculated box which has an expression (Amount*Price - Amount*Price*Discount) for that bill's price but it's seems like a big problem for me, and this mess is gonna make me crazy now.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Use form/subform arrangement for data entry. Review http://office.microsoft.com/en-us/ac...010098674.aspx

    Again, cannot use one query and one form to enter data into multiple tables.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 11-05-2012, 04:07 PM
  2. Replies: 7
    Last Post: 04-23-2012, 01:25 PM
  3. Replies: 3
    Last Post: 10-11-2011, 01:43 PM
  4. Replies: 9
    Last Post: 07-14-2011, 07:20 AM
  5. index/primary cannot contain null value
    By BinHDreW in forum Access
    Replies: 1
    Last Post: 05-26-2011, 08:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums