Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
In what system/application will your query be executed?Once imported this file is used in a query, this query now needs to be exported,
Private Sub btnExporttoExcel_Click()
On Error GoTo Err_Handler
'------------------------------------------------------
'------------------------------------------------------
' Export New Table to Excel
'------------------------------------------------------
'------------------------------------------------------
Dim strFileName As String
Dim strDateMin As String
Dim strDateMax As String
Dim strUPSpriority As Integer
strDateMin = Format(DLookup("Min([TrackingDate])", "tblTrackingParse"), "mmddyy")
strDateMax = Format(DLookup("Max([TrackingDate])", "tblTrackingParse"), "mmddyy")
strUPSpriority = InputBox("Enter the UPS Shipping Priority Number", "UPS Shipping Priority", "1")
strFileName = InputBox("Enter the Excel Spreadsheet File Name", "Enter File Name", "Initiated " & _
strDateMin & " to " & strDateMax)
Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim exAppWs As Worksheet
Dim rng As Excel.Range
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = CurrentProject.Connection
.CommandType = adCmdText
.CommandText = "SELECT UPPER(BoxNumber), UPPER(FileNumber), TrackingDate " & _
"FROM dbo.View_ParsedTrackingTableWithFileNumberPrefixDescription " & _
"WHERE (FileNumber <> '.BOX.END.') " & _
"AND (BoxNumber NOT LIKE 'NBC%') " & _
"AND (Len(FileNumPrefix) = 1)" & _
"AND (LEN(BoxNumber) < '30') AND (BoxNumberPrefix LIKE '1Z') " & _
"AND BoxNumberShipping LIKE '%" & strUPSpriority & "%'"
End With
Set rst = cmd.Execute ' now we have a recordset returned
If rst.BOF And rst.EOF Then
MsgBox "Nothing to export !"
Exit Sub
End If
Dim exCellApp As Excel.Application
Dim iCols As Integer
Set exCellApp = CreateObject("Excel.Application")
exCellApp.Visible = True
exCellApp.Workbooks.Add
exCellApp.AutoRecover.Enabled = False
exCellApp.Assistant.On = False
'------------------------------------------------------
'------------------------------------------------------
' Set Column Headings
'------------------------------------------------------
'------------------------------------------------------
exCellApp.Worksheets(1).Cells(1, 1).Value = "BoxNumber"
exCellApp.Worksheets(1).Cells(1, 2).Value = "FileNumber"
exCellApp.Worksheets(1).Cells(1, 3).Value = "TrackingDate"
'------------------------------------------------------
'------------------------------------------------------
' Populate the Spreadsheet
'------------------------------------------------------
'------------------------------------------------------
For iCols = 0 To rst.Fields.Count - 1
exCellApp.Worksheets(1).Cells(2, iCols + 1).Value = rst.Fields(iCols).Name
Next
exCellApp.Worksheets(1).Range("a2").CopyFromRecordset rst
exCellApp.Columns("C:C").Select
exCellApp.Selection.NumberFormat = "[$-409]d-mmm-yyyy;@"
exCellApp.Cells.Select
exCellApp.Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
exCellApp.Cells.EntireColumn.AutoFit
exCellApp.Range("A1").Select
'Debug.Print _
' "C:\" & Year(Date) & "\" & strFileName & ".XLS"
exCellApp.ActiveWorkbook.SaveAs Filename:= _
"C:\" & Year(Date) & "\" & strFileName & ".XLS", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
'exCellApp.Workbooks.Close
exCellApp.Quit
rst.Close
endit:
Exit Sub
Err_Handler:
If StandardErrors(Err) = False Then
BeepWhirl
MsgBox Err & ": " & Err.Description
End If
Resume endit
End Sub