Thanks for replying....here is my code
Private Sub BtnExcelStore_Click()
Dim loqd As QueryDef
Dim stSQL As String
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim stLinkCriteria As String
Dim stWhat As String
Dim stCriteria As String
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim objXL As Excel.Application
Dim objWkb As Workbook
Dim objSht As Worksheet
Dim strPurchaseOrder As String
Dim strStore As String
Dim strHDDescription As String
Dim strSize As String
Dim strSKU As String
Dim strQuantity As Long
On Error GoTo BtnExcelStore_Click_Err
stWhat = "": stCriteria = ","
Set frm = [Forms]![Frm_Pull Sheet]
Set ctl = frm!lstStorePO
For Each varItem In ctl.ItemsSelected
stWhat = stWhat & "'" & ctl.ItemData(varItem) & "'"
stWhat = stWhat & stCriteria
Next varItem
stLinkCriteria = CStr(Left$(stWhat, Len(stWhat) - Len(stCriteria)))
Set loqd = CurrentDb.QueryDefs("Qry_Store PO")
stSQL = "SELECT Orders.OrderID, Orders.PurchaseOrder, Orders.Status " &
_
"FROM Orders INNER JOIN Order_Details ON Orders.OrderID =
Order_Details.OrderID " & _
"WHERE (((Orders.PurchaseOrder) IN (" & stLinkCriteria & ")) And
((Orders.Status) = 1) And ((Orders.StoreID)= " & [Forms]![Frm_Pull
Sheet]![cboStore] & ")) " & _
"ORDER BY Orders.PurchaseOrder;"
loqd.SQL = stSQL
loqd.Close
Set rs1 = CurrentDb.OpenRecordset("SELECT DISTINCT [Qry_Store Purchase
Order Pull Sheet].Store, [Qry_Store Purchase Order Pull Sheet].PurchaseOrder
" & _
"FROM [Qry_Store Purchase Order Pull
Sheet] " & _
"ORDER BY [Qry_Store Purchase Order
Pull Sheet].PurchaseOrder;", dbOpenSnapshot)
Set objXL = New Excel.Application
With objXL
.Visible = True
Set objWkb = .Workbooks.Add
Set objSht = objWkb.Worksheets(1)
With objSht
.Name = "Pull Sheet"
'Format WorkSheet and assign Store #, Name to Excel
.Columns("A:A").Select
With Selection
.ColumnWidth = 31
End With
.Columns("B
").Select
With Selection
.ColumnWidth = 10
End With
.Columns("E:E").Select
With Selection
.ColumnWidth = 25
End With
.Columns("F:G").Select
With Selection
.ColumnWidth = 5
End With
.Columns("A:G").Select
With Selection.Font
.Name = "Comic Sans MS"
.SIZE = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("A1").Select
ActiveCell.FormulaR1C1 = "HOME DEPOT:"
With ActiveCell.Characters(Start:=1, Length:=25).Font
.Name = "Comic Sans MS"
.FontStyle = "Regular"
.SIZE = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("A2").Select
ActiveCell.FormulaR1C1 = "SHIP DATE:"
With Selection.Font
.Name = "Comic Sans MS"
.SIZE = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("B1:G1").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("B2:G2").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Range("A4:G5").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A4").Select
ActiveCell.FormulaR1C1 = "PLANT DESCRIPTION"
Range("B4").Select
ActiveCell.FormulaR1C1 = "SIZE"
Range("C4").Select
ActiveCell.FormulaR1C1 = "SKU"
Range("D4").Select
ActiveCell.FormulaR1C1 = "QTY."
Range("E4").Select
ActiveCell.FormulaR1C1 = "LOCATION"
Range("F4").Select
ActiveCell.FormulaR1C1 = "TAGS"
Range("G4").Select
ActiveCell.FormulaR1C1 = "TAGS"
Range("F5").Select
ActiveCell.FormulaR1C1 = "PSL"
Range("G5").Select
ActiveCell.FormulaR1C1 = "PIC"
Range("A5:G5").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Range("B1").Select
ActiveCell.FormulaR1C1 = rs1!Store
With ActiveCell.Characters(Start:=1, Length:=25).Font
.Name = "Comic Sans MS"
.FontStyle = "Regular"
.SIZE = 16
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("A6").Select
If Not rs1.BOF Then
rs1.MoveFirst
Do While Not rs1.EOF
strPurchaseOrder = rs1!PurchaseOrder
'Assign Purchase Order to Excel
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "PURCHASE ORDER:"
With ActiveCell.Characters(Start:=1, Length:=25).Font
.Name = "Comic Sans MS"
.FontStyle = "Regular"
.SIZE = 16
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
ActiveCell.Offset(0, 1).Select
Range(ActiveCell.Offset(0, 0).Address & ":" &
ActiveCell.Offset(0, 4).Address).Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
ActiveCell.FormulaR1C1 = strPurchaseOrder
With ActiveCell.Characters(Start:=1, Length:=25).Font
.Name = "Comic Sans MS"
.FontStyle = "Regular"
.SIZE = 16
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
ActiveCell.Offset(1, -1).Select
Set rs2 = CurrentDb.OpenRecordset("SELECT [Qry_Store
Purchase Order Pull Sheet].* " & _
"FROM [Qry_Store Purchase Order
Pull Sheet] " & _
"WHERE ((([Qry_Store Purchase
Order Pull Sheet].PurchaseOrder)='" & strPurchaseOrder & "'));",
dbOpenSnapshot)
If Not rs2.BOF Then
rs2.MoveFirst
Do While Not rs2.EOF
strHDDescription = rs2!HomeDepotDescription
strSize = rs2!SIZE
strSKU = rs2!SKU
strQuantity = rs2!ShippingQuantity
'Assign Store Purchase Order Details to Excel
ActiveCell.FormulaR1C1 = strHDDescription
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = strSize
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = strSKU
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = strQuantity
ActiveCell.Offset(1, -3).Select
rs2.MoveNext
Loop
rs2.Close
End If
rs1.MoveNext
Loop
rs1.Close
End If
End With
End With
Set rs1 = Nothing
Set rs2 = Nothing
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing