Problem with Insert

B

brianv

i am having trouble insert a rcd into a tbl using an expression on dbl click

Tbl: Ingredients
IngredientId autoNumber Primary Key
Ingredient text

These is the starting data in the tbl:
IngredientId Ingredient
10 salt
14 butter
15 milk


on a form i have a Text Box Named IngredientTB
i type data into the text box, onion, and then dbl click it.

event dbl click starts an express which looks like this:

Private Sub IngredientTB_DblClick(Cancel As Integer)
DoCmd.RunSQL "Insert INTO Ingredients(Ingredient) Values ('" &
Me.IngredientTB & "')"

Rem Refreshes form data
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

End Sub


when i do this a rcd gets added but the Ingredient value is blank.

here is the data now:
IngredientId Ingredient
10 salt
14 butter
15 milk
24



then i add another Ingredient like flour. after dbl clicking the row gets
added. now if i look at the tbl i still have the blank Ingredient and now i
have onion also.

here is the data now:
IngredientId Ingredient
10 salt
14 butter
15 milk
24
25 onion


it is like 1 value behind. i have no idea what could be going on.
 
T

tina

try the following SQL statement, as

DoCmd.RunSQL "INSERT INTO Ingredients ( Ingredient ) " _
& "SELECT '" & Me!IngredientTB & "'"

btw, if you would rather not see the "You are about to append..."
confirmation message, try using Execute rather than RunSQL, as

CurrentDb.Execute "INSERT INTO Ingredients ( Ingredient ) " _
& "SELECT '" & Me!IngredientTB & "'", dbFailOnError

hth
 
B

brianv

thanks, i got it to work. the data in the text box did not get set until i
hit enter. therefore when i typed into the empty text box and then dbl
click, the variable was still set to blank. so a blank got inserted. if i
typed, hit enter then dlb click it worked. i decieded to just type and then
click a button instead of dbl click the field. this worked better.

--
thanks
brian


tina said:
try the following SQL statement, as

DoCmd.RunSQL "INSERT INTO Ingredients ( Ingredient ) " _
& "SELECT '" & Me!IngredientTB & "'"

btw, if you would rather not see the "You are about to append..."
confirmation message, try using Execute rather than RunSQL, as

CurrentDb.Execute "INSERT INTO Ingredients ( Ingredient ) " _
& "SELECT '" & Me!IngredientTB & "'", dbFailOnError

hth
 

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

Top