TextBox

J

Julia82

I want to add the value of a textbox to an existing table. How can I do that?
Thanks!
 
J

Jack Leach

The best way is to bind the textbox to a field in the form's underlying
table. The next best way, if the said field isn't in the that particular
table, is to create a query and pull from both tables, and bind the textbox
to that.

If neither one of those works, you can use an INSERT INTO sql.

DoCmd.RunSQL "INSERT INTO TableName (Fieldname) VALUES (" & Me.TextBoxName &
")"

Be sure to insert the extra quotes required if the said textbox contains a
string.

hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Julia82

DoCmd.RunSQL "INSERT INTO database (User) VALUES (" & Me.txtuser & ")"

I get a sintax error.

I tryed also with:

DoCmd.RunSQL "INSERT INTO database (User) VALUES (' " & Me.txtuser & " ' ")"

Same thing.

Thanks!
 
J

Jack Leach

If you actually have a table named "database" and a field named "user", you
need to change those names. I'm almost positive those are both reserved
words. Even if they're not in the list, I still wouldn't be comfortable
using them. You should adopt a naming convention. Myself, I prefix all
table names with "tbl" and all field names with "fld". This keeps any
strange errors from happening.

As for the syntax error, the first line you have looks correct, assuming the
value of txtuser is a number. If not, try the second one, with a minor
modification (remove the quote before the last parenthese):

DoCmd.RunSQL "INSERT INTO tblDatabase (fldUser) VALUES (' " & Me.txtuser & "
')"


hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Julia82

This Worked great! thank you.

Now gives me a warning message with the following text:

You are about to append 1 row(s).
Once you click Yes, you can't use the Undo command to reverse the changes.
Are you sure you want to append the selected rows?

And I am pretty sure I don't want this warning on every record I am
submitting.

And another thing, when the text is implemented, let's say I am at the 1st
row, instead of setting the value to the first row, it's adding a new one on
row 2.

Thanks!
 
J

Julia82

Ok, I found that doing this:

DoCmd.SetWarnings False 'disable warnings
'Do your stuff here
DoCmd.SetWarnings True 'enable warnings

Can disable the warning message.

What do I do with the blank row though...!?
I want to make the change when doing DoCmd.RunSQL, to the active record, not
to the next one.
 
J

Jack Leach

I'm still not quite sure why you aren't using a bound control, but anyway...

INSERT INTO creates a new record. To update a record, you need some UPDATE
sql. It's almost the same:

"UPDATE Tablename SET Fieldname=' " & Me.Controlname & " ' "


http://www.blueclaw-db.com/accessquerysql/update_statement_sql.htm

Read the article... if you leave out a where clause all records will be
updated, unlike INSERT INTO which doesn't make use of a where clause.

hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Julia82

I am not using a bound control because the textbox that is inserting the
value in the table get's the text from a TempVar.

Maybe it's a bit "around the corner", but for now I did things working
pretty well with the help of you guys, learned much Access and I thank you
for that.

I'll see what is with this UPDATE you're talking about and I will get back
to you.

Thank you Jack!
 
J

Julia82

Wow! This works like a charm. Thanks a lot Jack! You've been a real help.

At the first look, seemed that the INSERT INTO syntax would do the job, but
seems that was missing the UPDATE "backup". :)
 

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