Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO problem: Syntax for multiple fields??

Status
Not open for further replies.

manda2753

IS-IT--Management
Mar 5, 2003
5
0
0
US
Hopefully I posted this in the right forum. (This is my first time actually posting :)

I have a form for account tracking info. Users add new records and edit existing ones. I want to have a table (called LOG) that logs each time a user clicks on the edit (or add) button. After trying every single code sample on INSERT INTO that I could fine here, I finally got one thing to work:

CurrentDb.Execute "INSERT INTO LOG ([Timestamp]) values ('" & Now() & "');"

I also have a User field in the log table that has a default value of =Environ("Username"), which pulls the windows logon name and inserts it into the User field.

So right now, the log table is giving me the time a user hit the edit button (the code's in the edit sub) and the windows logon name for the user.

My problem is that I would also like it to record just the simple words "Add" or "Edit" in the third field of the log table (Activity), depending on where the code is, of course.

I have tried every combination of quation marks, commas, parenthese, etc, and just cannot find the correct syntax. Only once did I get the code to where I did not get an error, and that was with:
CurrentDb.Execute "INSERT INTO LOG ([Timestamp, [Activity]]) values ('" & Now() & "', '" & Edit & "');"

But that put NOTHING in the log table!! No error, but also no fields filled in!!
I have tried MS Access help, and using the syntax they use in their code samples got me absolutely nowhere. I've searched numerous times here, also. Still no dice.

Someone please help me, if I see one more syntax error, I'm going to snap. This is the absolute last piece of code to figure out before I can roll this thing out. Sorry this was so long. Thank you!!

Amanda
 
use Access append query to create a query and then open view, SQL to see the SQL statement
 
I'm sorry, I'm better at VB than Access queries, what do you mean use append query? What do I query?
 
Thank you!! That actually put me on the right path! This ended up working:

CurrentDb.Execute "INSERT INTO LOG ( [Timestamp], Activity ) values ('" & Now() & "', '" & "Edit" & "');"

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top