View Full Version : Code Problem...


AndyG23
09-02-2009, 01:44 AM
Hi All,

I have built a form where a number of buttons execute similar tasks so the code behind one of the buttons is as follows:

Private Sub Cmd_Stage1_Archive_Click()

Dim usrname As String
Dim button As String
Dim dterange As String

usrname = Environ("Username")
button = "Arc1"
dterange = Text8 & " " & Text6

Call Log_Action(usrname, button, dterange)

MsgBox "Stage 1 Complete", vbOKOnly

End Sub


The problem lies here with the Log_Action function:


Function Log_Action(usrname, button, dterange) As String

Dim SQL As String

SQL = "INSERT INTO Arc_Log(User_ID, Arc_Type, Arc_Table) VALUES (usrname, button, dterange);"

DoCmd.SetWarnings False
DoCmd.RunSQL SQL
DoCmd.SetWarnings True

End Function

The Variable get passed to the function ok, but when the SQL runs I get requests for parameter values??

Can someone help with this please?

AndyG23
09-02-2009, 02:08 AM
Sorted... Needed to change the SQL to the following:

SQL = "INSERT INTO Arc_Log([User_ID], [Arc_Type], [Arc_Table]) VALUES (" & "'" & usrname & "'" & ", '" & button & "'" & ", '" & dterange & "'" & ");"