code for primary key check?

dat_guy

Registered User.
Local time
Today, 08:55
Joined
Jul 30, 2003
Messages
28
Hello,

Mine might be a simple question, but I am pretty new and have yet to find the answer elsewhere.

I'm trying to find some code to do the following:

If (primary key requirments NOT met ) Then
Me.Undo
End If

or something that will give the same result. I have just not been able to find the code to check for the pri key. The table this particular form is based on uses multiple fields for its primary key (its a child table). And I'm having trouble with Access attempting to save before record navigation.

thanks for any help
dat_guy
 
Thanx for the response.

This form is used to input data to a child table. I have a cmbBox that is used to pull a GroupID from a query and place that value into a txtBox for adding records to this child table. This GroupID is the foriegn key for the one-to-many relationship, and part of the primary key for this table. In the parent table it is the primary key.

Additionally, I have a cmbBox that is used to pull existing records from this child table for editing.

Seperatly, these two controls work fine. But if a user should ever, select a GroupID and not complete a new record, but instead choose to edit an existing record, they will get a
"XXXXX (one of the primary key fields) cannot contain a null value" error.

In simple steps:
1) select GroupID to create new record
2) decide not to create new record
3) select existing record to edit <--- errors

this error will halt in the afterupdate of the cmb that pulls up records. The problem, of course, is Access is trying to write a record without all the primary key fields filled. I just dont know how to fix it properly.

I found a bit of code, I think posted by you, to put into the form_beforeupdate.
Loosely:
If IsNull(Me.txtGroupName) Then
MsgBox "Group Name is required", vbOKOnly
Me.txtGroupName.SetFocus
Cancel = True
End If

There are 4 fields that make up the primary key for this table. I played with this a bit but never got it to work for my situation.

thank you for any help you can give
dat_guy
 
I didn't mean to make duplicate threads.
Here I was just looking for some little piece of code that I couldn't find. The other thread helped me fix the problem last night.

sry for any inconvenience
dat_guy
 

Users who are viewing this thread

Back
Top Bottom