21dewsbury
Dec 22 2008, 03:53 PM
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
Dec 22 2008, 03:57 PM
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
Dec 22 2008, 03:58 PM
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
Dec 22 2008, 04:20 PM
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
Dec 22 2008, 04:28 PM
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
Dec 22 2008, 04:39 PM
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
Dec 22 2008, 04:44 PM
..also ... is it possible that this is a variable name and not a control on a form ????
RDH
theDBguy
Dec 22 2008, 04:58 PM
...and if that's the case, the OP needs to drop the Me keyword, right?
...& sur1 &...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.