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
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