By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

Data Entry Form - Index/Primary key null value

P: 10
I have a form to create a new record for a training course. The form is based on one table that has 4 keys set to primary key.

The first combo box on the form allows selection of the course POP code and this then fills details on 2 list boxs for course module code and description. The course section can then be selected from another combo box (filtered by the value in the first combo box) . Finally the course session name is entered manually. These 4 make a primary key. (POPCode, ModuleCode, Section, Session).

Further details of trainer etc are also filled in a similar manner.

When all of the controls on the form are full (I have ensured they meet referential integrity rules) i still get an "Index/Primary key cannot contain null value" message. I do not understand why as all of the controls have control sources set to the underlying table adn all have a value assigned. Any help is appreciated...
Thanks
Oct 23 '06 #1
Share this Question
Share on Google+
12 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
I can't be sure because I've never set up a table with four primary keys but I imagine Access is having some problems with it. Why not just add a key 'ID' set to autonumber and make it the primary key.



I have a form to create a new record for a training course. The form is based on one table that has 4 keys set to primary key.

The first combo box on the form allows selection of the course POP code and this then fills details on 2 list boxs for course module code and description. The course section can then be selected from another combo box (filtered by the value in the first combo box) . Finally the course session name is entered manually. These 4 make a primary key. (POPCode, ModuleCode, Section, Session).

Further details of trainer etc are also filled in a similar manner.

When all of the controls on the form are full (I have ensured they meet referential integrity rules) i still get an "Index/Primary key cannot contain null value" message. I do not understand why as all of the controls have control sources set to the underlying table adn all have a value assigned. Any help is appreciated...
Thanks
Oct 23 '06 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
By the way you can still set the other keys to required if that's what you're worried about but they shouldn't need to be part of the primary key.



I can't be sure because I've never set up a table with four primary keys but I imagine Access is having some problems with it. Why not just add a key 'ID' set to autonumber and make it the primary key.
Oct 23 '06 #3

P: 10
thanks,
true that it was not needed, it works fine with just 1 primary key.
cheers
Oct 25 '06 #4

P: 10
I have a form to create a new record for a training course.
The first combo box on the form allows selection of the course POP code and this then fills details on 2 list boxs for course module code and description.

Problem: the 2 controls above are not taking the requery-ed value through to the table. The proper data is displayed on the form but when i look at the table being updated, the data is not present. If i (mouse) click on the controls then the value is passed to the table, but if i tab through it, it still isnt passed to the table!
Is there a way to simulate the controls being clicked?

very confused.....
Oct 25 '06 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
Firstly

What is the Control Source property of each of these fields set to?

regardless of any action if the control source is set to the field in the table then the field should update.
Oct 25 '06 #6

P: 10
the control source for each control is set to the appropriate field of the table.
Also, the bound column is set to 0.
The value that is selected is from an SQL statement in the controls row source. This is requery-ed after selection of the value in the first combo.
baffling!





Firstly

What is the Control Source property of each of these fields set to?

regardless of any action if the control source is set to the field in the table then the field should update.
Oct 26 '06 #7

MMcCarthy
Expert Mod 10K+
P: 14,534

Also, the bound column is set to 0.
The bound column needs to be set to 1. The first column is only refered to a 0 when its being used programmatically.

e.g. Me.combobox.Column(0)
Oct 26 '06 #8

P: 10
thanks, but it still doesnt change things, when i arrow to the next record after entering details, the values in the controls that dont update stay on the form - mean anything to you?
Thanks again,
Aidan
Oct 27 '06 #9

MMcCarthy
Expert Mod 10K+
P: 14,534
What code are you using on the combo box and in what event did you put it.

Is there any coded event on the two text boxes.
Oct 27 '06 #10

P: 10
Hi,
sorry i have been away for a few days.
there is a simple code on the combo to requery the 2 controls that i am having the problem with, its placed 'OnChange':

Private Sub POPCode_Change()
Me.ModuleDescription.Requery
Me.ModuleCode.Requery
End Sub

You think this could be thew problem?
thanks
Aidan
Nov 1 '06 #11

MMcCarthy
Expert Mod 10K+
P: 14,534
Change to the AfterUpdate event and see if that makes a difference.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub POPCode_AfterUpdate()
  3. Me.ModuleDescription.Requery
  4. Me.ModuleCode.Requery
  5. End Sub
  6.  
  7.  
Nov 1 '06 #12

P: 10
No help either...this is the row source of one of the controls being requeryed:

SELECT tblTrainingModules.ModuleCode FROM tblTrainingModules WHERE tblTrainingModules.POPCode = Forms!frmTrainingSessions1.POPCode

make any difference?
Nov 1 '06 #13

Post your reply

Sign in to post your reply or Sign up for a free account.