Is Form2 a subform on Form1, or what exactly? It may be easier to follow if
you describe the forms.
Is error message 3201 being generated by the Not In List event? I assume so,
but you didn't specify. A further assumption is that it happens on the
Execute line of code.
When I have used Not In List to update a table it has been either a lookup
table or a top level table in a relationship hierarchy, so related records do
not come into play. It sounds as if you need to use the Not In List event to
generate a child record, so first you need to create a parent record.
If that is the case, I think you will need to open a recordset to add the
parent record before using the existing code to update the combo box list..
esee,
If you could Top-Post during this thread with me, that would help us
[quoted text clipped - 73 lines]
Do you have a way for me to do this?
I don't know what you mean by Top Post. I'm using Google Groups and
it seems to be setup to enter my reply at the bottom of the list.
You are not understanding my problem.
FORM1 SQL
SELECT zIngredients.IngredientID, zIngredients.NeedIT,
zIngredients.Ingredient, zIngredients.LocationID
FROM zIngredients
ORDER BY zIngredients.Ingredient;
Private Sub cboName_NotInList(NewData As String, Response As Integer)
Dim sqlAddState As String, UserResponse As Integer
Beep
UserResponse = MsgBox("Do you want to add this value to the list?",
vbYesNo)
If UserResponse = vbYes Then
sqlAddState = "Insert Into qIngredients ([Ingredient])values
('" & NewData & "')"
CurrentDb.Execute sqlAddState, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
When "Not In List" is executed, I get a run-time error 3201, you
cannot add or change a record because a related record is required in
zLocations.
This is why I'm using FORM2, to update zLocations with Ingredient and
a Location. I then want to go back to FORM1
to select an Ingredient.
Okay, I'll try my best to provide you with the necessary information
to help me. Keep in mind, that this is working fine except for one
minor little thing that I want to happen. I'll show you code and then
make comments as to what happens, and what I want to happen.
FORM1 Record Source SQL
SELECT zIngredients.IngredientID, zIngredients.NeedIT,
zIngredients.Ingredient, zIngredients.LocationID
FROM zIngredients
ORDER BY zIngredients.Ingredient;
cboName is an unbound combo box with the following Row Source
SELECT qIngredients.IngredientID, qIngredients.Ingredient
FROM qIngredients
ORDER BY qIngredients.Ingredient;
cboName has a " On Not In List" event as follows:
Private Sub cboName_NotInList(NewData As String, Response As Integer)
Dim byt As Byte, stDocName As String
If OldNewData = NewData Then
OldNewData = ""
End
Else
OldNewData = NewData
End If
Me.Text23 = NewData
Me.cboName.Undo
byt = MsgBox("Do you want to add a new Ingredient to the Lookup
Table?", vbYesNo)
If byt = vbYes Then
Response = acDataErrContinue
stDocName = "frmAddIngredients2"
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
End If
End Sub
Text23 saves the value entered in cboName for use on FORM2
FORM2 Record Source SQL
SELECT zIngredients.IngredientID, zIngredients.NeedIT,
zIngredients.Ingredient, zIngredients.LocationID
FROM zIngredients
ORDER BY zIngredients.Ingredient;
The On Load Event of FORM2
Private Sub Form_Load()
If CurrentProject.AllForms("ShoppingList").IsLoaded Then
strWhichForm = "ShoppingList"
Me.Ingredient.Value = Forms![ShoppingList]![Text23]
End If
End Sub
This fills the text box "Ingredient" with the saved value that fired
the "On Not In List" event on FORM1
I then specify the Location that this Ingredient belongs to, and exit
FORM2. I now have a new ingredient that can be used on FORM1
When I exit FORM2, FORM1 fires the Activate Event, which does a
Refresh, and Requery. The new ingredient is now available to be used
by FORM1.
THE MINOR PROBLEM
I do not want to manually enter the New Ingredient again. I want to
somehow fill the cboName with the New Ingredient, and then press enter
to move on to the next field. Minor problems are worth fixing too...
Thanks for any help you may provide.