Results 1 to 6 of 6
  1. #1
    yayay is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    3

    Index or primary key cannot contain a Null value!!!!

    I am currently trying to insert a record into my database. The fields in my table are RecordID, BillNumber, CongresspersonID, and Vote. RecordID is the primary key and its data type is Autonumber. It says the primary key can't be null, but it's not! It wouldn't let me upload the database because it says it's too big. This is my code:

    Private
    Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.ClickcongressCommand.CommandText = "Insert into votingRecord(BillNumber, CongresspersonID, Vote) Values('" & ComboBox1.Text & "', '" & TextBox1.Text & "', '" & ComboBox2.Text & "')"


    Dim numOfRecordsChanged AsInteger = congressCommand.ExecuteNonQuery()
    If numOfRecordsChanged = 1 Then
    MsgBox("A new voting record has been added")
    Else
    MsgBox("Error: Please contact administrator")
    EndIf
    EndSub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Are these fields all text datatype? If not, don't use apostrophe delimiters.

    Also, don't use the .Text property, .Value is what you want but since .Value is the default, don't need to even type it.

    Did you run Compact & Repair and zip the db? Zip still too big, copy db and remove data (leave a few records for testing).
    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
    yayay is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    3
    The fields are all text datatype.
    Here is the attachment:
    Congress1.accdb


    Quote Originally Posted by June7 View Post
    Are these fields all text datatype? If not, don't use apostrophe delimiters.

    Also, don't use the .Text property, .Value is what you want but since .Value is the default, don't need to even type it.

    Did you run Compact & Repair and zip the db? Zip still too big, copy db and remove data (leave a few records for testing).

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    That db has three tables - no queries, forms, or code to analyse.
    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.

  5. #5
    yayay is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    3
    All of my code is in Visual Studio. I'm inserting into the database from my project in Visual Studio.

    Quote Originally Posted by June7 View Post
    That db has three tables - no queries, forms, or code to analyse.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I have never coded behind Visual Studio. If you provide the VS file, might be able to help. Would be a learning experience for me.

    Or might have better luck posting to a VS forum.
    Last edited by June7; 11-05-2012 at 08:15 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.

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

Similar Threads

  1. Replies: 7
    Last Post: 04-23-2012, 01:25 PM
  2. Replies: 2
    Last Post: 04-23-2012, 01:04 AM
  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