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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting directly into tables

Status
Not open for further replies.

8441

Technical User
May 9, 2001
54
GB
I have a table called audit_log. This table has three fields. Ref, Dateofentry, Action. My plan is this.

The user enters duty details into a form which is linked to temp_duty_details. On this form at the bottom are some buttons which are set to open up different mail merge documents in word. Want I want to do is when a user presses one of these buttons an entry is made in the audit_log table. The ref is taken from the form but the date_of_entry would be Now() and the action would be text such as "monitoring form printed" The problem I have is getting the date and action entered directly into the audit_log table using code or SQL?

Any ideas.


Thanks
 
Try this:

DoCmd.RunSQL "Insert Into [audit_log] (Ref, Dateofentry, Action) Select '" & Me!Ref & "' AS Ref, Now() AS Dateofentry, '" & Me!Action & "' AS Action "

Good luck! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Many thanks. I had a problem with the Action part as it was free text and not bound to an object on the form. In typing my reply I had a thought. I put the text I required in a variable within the code and referenced this in the SQL statement. It worked. My code now looks like this


DoCmd.RunSQL "Insert Into [Audit_Log] (Duty_Ref, Date_of_entry,Action_Performed) Select '" & Me!Duty_Reference & "' AS Duty_Ref, Now() AS Date_of_entry, '" & ActionText & "' AS Action_Performed "


ActionText is set further up as ActionText="Monitor Form Printed"

Thanks for the help.
Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top