Help: Query in VBA requests parameter for some users, not others

cricketbird

Registered User.
Local time
Today, 16:27
Joined
Jun 17, 2013
Messages
118
I have a function that inserts some data into a table and logs the user who made the change (based on their windows username). This query works fine for users whose windows username is numbers only, but fails for those who have text in their usernames. When users with text in their names run this code, they get a "Enter parameter" message box whose prompt is their windows username. Then, whatever they type in the box gets filled into the table.

The field that these are being saved in is a text field, so I'm not sure why this is failing. Here is the code:

Code:
Public Sub SaveHistoryNote()

Dim strQry1 As String
Dim myTime As Date
Dim myUser As String

myTime = Now()
myUser = (Environ$("Username"))
strQry1 = "INSERT INTO TblChangeHistory (StartDate, ORDERID, ITEMID, AMOUNT, UNITID, SORT, WinUserID ) " & _
              "SELECT #" & myTime & "#, ORDERID, ITEMID, AMOUNT, UNITID, SORT," & myUser & _
              " FROM [OrderSubTable]" & _
              " WHERE [ORDERID] = " & Forms![SearchForm].OrderID & ";"

DoCmd.SetWarnings False
    DoCmd.RunSQL strQry1
DoCmd.SetWarnings True

End Sub

The WinUserID field of the TblChangeHistory table has a data type of "Text". Folks are either running WinXP or Win7, and either Access 2007 or 2010. However, that doesn't appear to be affecting this.
 
Try:

"...SORT,'" & myUser & "'" & _
 
Worked perfectly. Thanks!
 

Users who are viewing this thread

Back
Top Bottom