Question : Putting a variable into SQL

See code attached.
I am building a simple audit log of who logs into the database and when.

I am trying to insert a variable into an SQL statement.

The DoCmd.RunSQL is NOT inserting the computer_name variable - despite the fact that the "computer_name" variable has a good value.  Instead I am prompted for a value for "computer_name".

How do I get my "computer_name" correcty into my SQL statement??
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Public Function autoexec()
Dim Computer_Name As String * 12
        Dim user_name As String * 12
        Dim strname As String * 255
        
        GetUserNameA user_name, Len(strname)
        GetComputerNameA Computer_Name, Len(strname)
        DoCmd.RunSQL ("insert into audit_log (who_logged_in,when_logged_in) values ([computer_name],now())")

End Function

Answer : Putting a variable into SQL

DoCmd.RunSQL ("insert into audit_log (who_logged_in,when_logged_in) values ('" & computer_name & "',now())")
 
Random Solutions  
 
programming4us programming4us