troubleshooting Question

How do I eliminate "Index or Primary Key cannot contain a null value?"

Avatar of sarahellis
sarahellis asked on
Microsoft AccessVB Script
19 Comments2 Solutions3585 ViewsLast Modified:
I have a form that displays an Item.  It has a subform that should show all units with this item, and allow users to add units to the item.  I want the subform to show any records, who's item matches the record that the form is currently displaying.  TblRollout has a unique field "key" which is a combination of the UnitID and ItemID.  

The recordsource for the subform is: "select Unitid, item from tblRollout order by item" It is a dynaset.
I can't find a place to put the code that adds the record without getting the above error.  I've tried in the form Before Update, in the textbox Before Update, and lots of other places.  The record does actually get added to the table, right before the error appears.  I think it has to do with the subform trying to add the record on its own.  I'd really appreciate any help you can offer.  Thank you!

The code that adds the record is:
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("tblrollout", dbOpenDynaset)
    With rs
        If rs.RecordCount > 0 Then
        End If
        !Item = Forms!frmUpdateTests1.txtTestid
        !UnitID = Me.[UnitID]
        !Key = Trim(Me.UnitID) & "-" & Trim(Forms!frmUpdateTests1.txtTestid)
        !Qty = 1
        !orddate = Date
    End With
Join our community to see this answer!
Unlock 2 Answers and 19 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros