T
Tal
Hello all,
Thanks in advance!
So I have a form with a subform, depending on a selection in a combo box, I
want to either create a new entry in the table related to the subform or not.
The code I have written governing this is as follows:
Private Sub cboKeyDinnerStatus_LostFocus()
Dim dbase As DAO.Database
Dim recSet As DAO.Recordset
Set dbase = CurrentDb()
Set recSet = dbase.OpenRecordset("Select * from [tblDinnerBook] where
[keyDinner] = " & Me.keyDinner)
If recSet.RecordCount > 0 Then
Exit Sub
Else
If Me.cboKeyDinnerStatus = 3 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
If Me.cboKeyDinnerStatus = 6 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
If Me.cboKeyDinnerStatus = 8 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
If Me.cboKeyDinnerStatus = 9 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
End If
End Sub
I am getting the error 3201 - You cannot add or change a record because a
related record is required in table "tblDinner"
If I hit end with the error message, it allows me to select the option and
creates the record. However, I get the error message a few more times and the
subform does not update to reflect the newly-created record.
Any help is appreciated.
Thanks,
Tal
Thanks in advance!
So I have a form with a subform, depending on a selection in a combo box, I
want to either create a new entry in the table related to the subform or not.
The code I have written governing this is as follows:
Private Sub cboKeyDinnerStatus_LostFocus()
Dim dbase As DAO.Database
Dim recSet As DAO.Recordset
Set dbase = CurrentDb()
Set recSet = dbase.OpenRecordset("Select * from [tblDinnerBook] where
[keyDinner] = " & Me.keyDinner)
If recSet.RecordCount > 0 Then
Exit Sub
Else
If Me.cboKeyDinnerStatus = 3 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
If Me.cboKeyDinnerStatus = 6 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
If Me.cboKeyDinnerStatus = 8 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
If Me.cboKeyDinnerStatus = 9 Then
recSet.AddNew
recSet!keyDinner = Me.keyDinner
recSet.Update
End If
End If
End Sub
I am getting the error 3201 - You cannot add or change a record because a
related record is required in table "tblDinner"
If I hit end with the error message, it allows me to select the option and
creates the record. However, I get the error message a few more times and the
subform does not update to reflect the newly-created record.
Any help is appreciated.
Thanks,
Tal