combo box and subform giving error

hotmalepiyush

Registered User.
Local time
Today, 07:42
Joined
Jun 3, 2008
Messages
60
hello,
i am having a strange problem
i have table with PK: name+phone number.
i have a form which has a combo box and a subform
combo box is used to select a name...
on updation of this combo box the subform finds related details..
when i click on any textbox to update etc.. i get an error "index or primary key cannot contain a Null value.

also suppose there are more than 1 person called jim.. then i cannot go to next record.. as the same error msg keeps popping.

next when i try closing this form i get an error message saying u cannot record this record.
i no where try to add any new record to my table

please suggest what might be possibly wrong

here's the code i am using on the cobo box:
Code:
Sub SetFilter()
Dim LSQL As String
 
LSQL = "select * from FairDB"
LSQL = LSQL & " where Name = '" & cboSelected & "'"
 
Form_FindByName.RecordSource = LSQL
 
End Sub
Private Sub cboSelected_AfterUpdate()
 
'Call subroutine to set filter based on selected CustomerID
SetFilter
 
End Sub
Private Sub cmdClose_Click()
'Close form
DoCmd.Close
 
End Sub
Private Sub Form_Open(Cancel As Integer)
 
'Call subroutine to set filter based on selected CustomerID
SetFilter
 
End Sub
 
Morning,

my initial thought is that your explanation describes 2 Primary Keys in your table "Name" & "number". is this correct?

if so,

wouldnt you be better having only 1 primary key "ContactID" and Name & Number be a field only? i'm guessing that you may not have data in both fields in all records hence the primary key cannot have a null value.

secondly

if name is a primary key and you have 2 people called Jim, then you have duplicated data in the primary key field which is not allowed so access doesnt really know where to go.

i would suggest 1 primary key with an autonumber which cannot be duplicated. then, you can have 50 jims if you need but the record will be unique to the ContactID only.

failing that, can you post a sample db to have a look at the problem?


regards,

Nigel
 
Last edited:
hey nigel.. thanx for coming for my rescue.. actually by removing control source from the combo box.. my problem got solevd
 

Users who are viewing this thread

Back
Top Bottom