Hi Guys,
I have a database with nearly 50,000 records in including sub forms that are connected to the main form, what I want to be able to do is, have a button on my switchboard that when clicked with export any records over 6 months into an Excel Spread Sheet. Is this possible at all and if so, How do I do it.
I only have basic knowlege of access so simple explanation is needed, sorry xx
I found this code, can anyone tell me if it is the correct one to use, I also need to know how to create the query for the button, I can do basic queries but I need the button to on export anything that is 6 months +.
I would appricate someones help, you may need to be patient with me lolPublic Sub ModifyExportedExcelFileFormats(sFile As String) On Error GoTo Err_ModifyExportedExcelFileFormats Call ModifyExportedExcelFileFormats("X:\file.xls") Application.SetOption "Show Status Bar", True vStatusBar = SysCmd(acSysCmdSetStatus, "Formatting exported files... please wait.") Dim xlApp As Object Dim xlSheet As Object Set xlApp = CreateObject("Excel.Application") Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1) With xlApp .Application.Sheets("DTDs Export data Archive").Select .Application.Cells.Select .Application.Selection.ClearFormats .Application.Rows("1:1").Select .Application.Selection.Font.Bold = True .Application.Cells.Select .Application.Selection.RowHeight = 12.75 .Application.Selection.Columns.AutoFit .Application.Range("A2").Select .Application.ActiveWindow.FreezePanes = True .Application.Range("A1").Select .Application.Selection.AutoFilter End If .Application.ActiveWorkbook.Save .Application.ActiveWorkbook.Close .Quit End With Set xlApp = Nothing Set xlSheet = Nothing vStatusBar = SysCmd(acSysCmdClearStatus) Exit_ModifyExportedExcelFileFormats: Exit Sub Err_ModifyExportedExcelFileFormats: vStatusBar = SysCmd(acSysCmdClearStatus) MsgBox Err.Number & " - " & Err.Description Resume Exit_ModifyExportedExcelFileFormats End Sub
Shaxx
xx
I would use the following procedure.
Create your query using the following format. Substitute your field names and table names accordingly.
Then in the on click event for your command button use the following codeSelect * from YourTableName WHERE YourDateField < Dateadd("m",-6,date())
This will export your query to your local desktop as an excel spreadsheet in 2007 formatDim reportName As String Dim theFilePath As String reportName = "Your Query Name" theFilePath = "c:\Set your Path to you desktop here" theFilePath = theFilePath & reportName & "_" & Format(Date, "yyyy-mm-dd") & ".xlsx" DoCmd.TransferSpreadsheet acExport, 10, reportName, theFilePath, True MsgBox "Look on your desktop for the report."
Alan
Last edited by alansidman; 01-30-2012 at 07:55 AM.
Alan
Click the * below to say thanks.
Database Principles
Pivot Table Tips
Good Excel Video Tutorials
Sumifs or SumProduct
DataPig Access Tutorials
MS Query Tutorial
Worst Pie Chart Ever?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks