Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index or Primary key cannot contain Null value

Status
Not open for further replies.

JimTheProgrammer

Programmer
Oct 18, 2000
11
US
I have a datasheet subform on my main form that gets this nasty message if you enter data into a field, delete it (or backspace it out) and then try to click on the main form. I know the causes and I think I know how to trap it, but I don't know how to tell it to give up altogether and let me out of the subform.

Help
Jim
 
Try hitting the "esc" key or adding a "undo" commmand button on your form
 
I'm after a automatic solution. I can highlite the record (after putting any character in the key field) and delete the record. The point is I don't want the user to have to do anything. If they enter a null, I want to exit the the input area with out further operator intervention.
 
Try something like the following in the LostFocus event of the subform:

Private Sub Form_LostFocus()
If IsNull(Me![PrimaryKeyField]) Then
Me.Undo
End If
End Sub

I haven't tested this code, so I can't guarantee it will work in your case, but it's something to try, anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top