Here is another way: (air code)
Code:
Public Sub test_ss()
Dim rst As DAO.Recordset
Dim MySQL As String
Dim SaveToFile As String
'.
'.your other code
'.
'
MySQL = "SELECT TimesheetTable.ID, TimesheetTable.sUser, UserNames_tbl.WorksNumber,"
MySQL = MySQL & " TimesheetTable.Activity, TimesheetTable.Hours, TimesheetTable.Project,"
MySQL = MySQL & " TimesheetTable.[Task Date], TimesheetTable.Description, TimesheetTable.Approved"
MySQL = MySQL & " FROM UserNames_tbl INNER JOIN TimesheetTable ON UserNames_tbl.sUser = TimesheetTable.sUser"
'open the recordset
Set rst = CurrentDb.OpenRecordset(MySQL)
If rst.BOF And rst.EOF Then
'no records returned
MsgBox "Sorry, you do not have access to this function", vbOKOnly, "Important Information"
Else
' create save to file name
SaveToFile = "N:\TimesheetDatabase\" & Format(Date, “ddmmyyyy”) & ".csv"
DoCmd.OutputTo acOutputQuery, rst, acFormatTXT, SaveToFile, True
End If
'clean up
rst.Close
Set rst = Nothing
End Sub