Error 3201 Help!!

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
 
G

GBA

if tblDinner is the main form's record source...then it is saying that you
are writing a new subform record but without first establishing a record in
the main form

you can't write into the child table without first writing into the parent
table...
 
T

Tal

Hi GBA,

Thanks for your response.

But once I have selected something in the cboKeyDinnerStatus, isn't a record
created? So by the time I'm at the LostFocus event, the record should already
exist, right?

Thanks again!

GBA said:
if tblDinner is the main form's record source...then it is saying that you
are writing a new subform record but without first establishing a record in
the main form

you can't write into the child table without first writing into the parent
table...

Tal said:
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
 
G

GBA

assuming your combobox is set up to look up an existing record of the main
form then I agree with you; the record in the parent table defacto must
exist....

that would make me think therefore that in your code to make the new subform
record that the cross reference to the main form's record is not being
entered into the appropriate subform's field...

assuming you can visually see this field in the subform....verify this...

Tal said:
Hi GBA,

Thanks for your response.

But once I have selected something in the cboKeyDinnerStatus, isn't a record
created? So by the time I'm at the LostFocus event, the record should already
exist, right?

Thanks again!

GBA said:
if tblDinner is the main form's record source...then it is saying that you
are writing a new subform record but without first establishing a record in
the main form

you can't write into the child table without first writing into the parent
table...

Tal said:
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
 

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

Similar Threads

backing up the code mods 1
How do I debug VB error #80004005 1
Error 3201 1
RecordSets 1
Error 3061 2
Error when assigning Null fields to variables. 3
Erro 3201 3
HELP: Run-time error '-2147352567 (80020009): 3

Top