Error Message

B

Bernd

Hi,
I've some trouble with adding a record to a related
table.
I've two related comboboxes in my form, the first
contains a list of patient names and the second contains
the related visit dates of each patient, wich can be also
more then one per person.
So I have two tables:

tblPatient:
PatientNameID => autonumber
PatientName => text

tblProducts:
PatientID => autonumber
PatientNameID => Number
Date => Date/Time

with a relationship (one to many) between PatientNameID
of the two tables.

When i click on a patientname in the first comboboxes, in
the second table there are automaticly displayed the
related visit dates (thanks to a code inserted on After
Update property in the first combo).
When I add a new name in the first combo, everything is
all right (thanks to a code inserted in the NotInList
property of the first combo), but when I try to add a
related date in the second combo, Access gives me the
following error message:

"You cannot add or change a record because a related
record is required in table"

Why is happen this (the reason is sure the relationship
between the to tables, but I need it to made functionally
my database)? And how can I resolve it?

The code that I insert in the NotInList property of the
second combo is the following:

Private Sub Combo2_NotInList(NewData As String, Response
As Integer)
Dim strSQL As String
Dim i As Integer
Dim Msg As String

'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub

Msg = "'" & NewData & "' is not currently in the list." &
vbCr & vbCr
Msg = Msg & "Do you want to add it?"

i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Book
Category...")
If i = vbYes Then
strSQL = "Insert Into tblPatient ([PatientName])
values ('" & NewData & "')"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If

End Sub

Please help me.
Thanks
Bernd
 
G

Guest

Bernd,
It sounds like you have a subform on a Masterform. If this is the case, and
you have default values in any controls on the subform...
I've had the same problem and got an answer through the forum at
www.utteraccess.com
This is a bug in Access that only happens when you have any default values
in any of the Controls (text boxes etc) on the subform. Remove all default
values and it works. Another condition that seems to be necessary for the Bug
is that the One side of the relationship be an Autonumber ID field. I've
tried to find out if MS have released a bug fix yet, but so far no joy.
Hope this helps, Nat.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top