Trying to select from a table then export with VBA

shabbaranks

Registered User.
Local time
Today, 17:25
Joined
Oct 17, 2011
Messages
300
Hi guys,

Im trying to get this code to select from a table based on a field and then export. I know I can do it using a query but would like to further my sql and vba knowledge. Can anyone assist please? The code I have currently is
Code:
    Dim strPasswd
    strPasswd = InputBox("Enter Password", "Restricted Form")
    If strPasswd = "" Or strPasswd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
    End If
    If strPasswd = "export" Then
    DoCmd.RunSQL Mysql = "SELECT TimesheetTable.sUser, TimesheetTable.Activity, TimesheetTable.Hours, TimesheetTable.Project, TimesheetTable.[Task Date] FROM TimesheetTable WHERE (TimesheetTable.Approved)=True;"
    DoCmd.OutputTo acOutputQuery, "ExportCSVQuery", "MicrosoftExcel(*.xlsx)", "D:\Test\" & Format(Date, "ddmmyyyy") & ".csv", False, ""
    DoCmd.OpenQuery "UpdateExportedQuery"
    Else

Thanks
 
Ah theres me not thinking straight, all I needed to do was to add criteria to the query which met what I was looking to output - sorry :)
 

Users who are viewing this thread

Back
Top Bottom