thanks, but i still have the same problem. in my last example i use just
hard coding string values in to get the syntax right. here is a more
acturate ex:
Tbl:
Ingredients
IngredientId autoNumber primary key
Ingredient text
Note text
in a tab on my form i have 2 text boxes
AddTabIngredient
AddTabNote
(Both of these text boxes are on the tab named AddTab.
The tab also has a button which when clicked executes:
Private Sub AddTabAddIngredientButton_Click()
On Error GoTo Err_AddTabAddIngredientButton_Click
CurrentDb.Execute "INSERT INTO Ingredients ( Ingredient, " _
& "Note ) Values (" _
& "'" & Me!AddTabIngredient & "', " _
& "'" & Me!AddTabNote & "')", dbFailOnError
Me!AddTabIngredient = ""
Rem Refreshes form data
DoCmd.RunCommand acCmdRefresh
Exit_AddTabAddIngredientButton_Click:
Exit Sub
Err_AddTabAddIngredientButton_Click:
MsgBox Err.Description
Resume Exit_AddTabAddIngredientButton_Click
End Sub
when i click the button i get a message:
Syntax error in Insert INTO statement
--
thanks
brian
Brian Bastl said:
Assuming you have Ingredient and Note in Ingredients table, and you have
controls on your form named Ingr2 and note2 (and they are text values) then
the following should work:
CurrentDb.Execute "INSERT INTO Ingredients ( Ingredient, " _
"Note ) Values (" _
"'" & Ingr2 & "', " _
"'" & note2 & "')", dbFailOnError
otherwise, if Ingr2 and note2 are numeric values, then
CurrentDb.Execute "INSERT INTO Ingredients ( Ingredient, " _
"Note ) Values (" _
"" & Ingr2 & ", " _
"" & note2 & ")", dbFailOnError
HTH,
Brian