Full Version: Insert into query. Inserting table value
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
21dewsbury
This should be easy ... ??

See the following syntax which is activated by a double-click in a form.
It works fine except for the very last "sur1" but.

"sur1" actually refers to persons "surname" and is held on a table in the form.

DoCmd.RunSQL "INSERT INTO HISTORY (ACC_User,date_of_action, comment_1 ) VALUES (currentuser(),now(),sur1) "


When I run the above SQL I am prompted to input a value for "sur1". I do not want to be prompted at all! I merely want to write the value held in "sur1" to the table HISTORY.

I have tried other syntax but get similar problems.
theDBguy
Hi,

Not sure what you're trying to do, but to just comment on your syntax, it should be something like this:

"INSERT INTO HISTORY (ACC_User, date_of_action, comment_1) VALUES (currentuser(), now(), '" & Me.sur1 & "')"

(untested)
Hope that helps...
R. Hicks
Hmmm .... try:

CODE
DoCmd.RunSQL "INSERT INTO HISTORY (ACC_User,date_of_action, comment_1) VALUES (currentuser(),Now(),'" & Me.sur1 & "')"


Also ... you are using RunSQL .... I recommend you use the execute method instead ...

Example:
CODE
CurrentDb.Execute "INSERT INTO HISTORY (ACC_User,date_of_action, comment_1) VALUES (currentuser(),Now(),'" & Me.sur1 & "')", dbFailOnError

RDH
21dewsbury
Thanks , there was a basic flaw in my syntax.

However now I get a run time error 2467

DoCmd.RunSQL "INSERT INTO HISTORY (ACC_User,date_of_action, comment_1 ) VALUES (currentuser(),now(),'" & Me.Sur1 & "') "

"Sur1" is a valid field name but it is causing the error.

Any thoughts?
R. Hicks
Copy and paste exactly as I have it here:

CODE
DoCmd.RunSQL "INSERT INTO HISTORY (ACC_User,date_of_action, comment_1) VALUES (currentuser(),now(),'" & Me.Sur1 & "')"

RDH
theDBguy
Perhaps "sur1" is not the name of the control on your form. If that is the case, you'll have to replace it with its proper name. For example:

Me.Text1

Hope that helps...
R. Hicks
..also ... is it possible that this is a variable name and not a control on a form ????

RDH
theDBguy
...and if that's the case, the OP needs to drop the Me keyword, right?

...& sur1 &...

sad.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.