Snappy1263
Registered User.
- Local time
- Today, 02:40
- Joined
- Dec 8, 2015
- Messages
- 130
So sorry,
i sent it from my work email.
thanks,
i sent it from my work email.
thanks,
Function SendToExcel(strTQName As String, strSheetName As String)
' strTQName is the name of the table or query you want to send to Excel
' strSheetName is the name of the sheet you want to send it to
Dim rst As DAO.Recordset
Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object
Dim fld As DAO.Field
Dim lngMaxRow As Long
Dim lngMaxCol As Long
Dim strPath As String
On Error GoTo Err_Handler
'Location of Template
strPath = "G:\SUE'S STUFF\WORKING DESKTOP\2016 WESTLAND\WESTLAND EXPORT\Book1.xls"
Set rst = CurrentDb.OpenRecordset(strTQName)
Set ApXL = CreateObject("Excel.Application")
Set xlWBk = ApXL.Workbooks.Open(strPath)
ApXL.Visible = True
Set xlWSh = xlWBk.Worksheets(strSheetName)
xlWSh.Range("I1").Value = Me.ID
xlWSh.Range("I2").Value = Me.[COVER PART NUMBER]
xlWSh.Range("I3").Value = Me.[MODELS.DESCRIPTION]
rst.MoveFirst
xlWSh.Range("A8").CopyFromRecordset rst
' selects the first cell to unselect all cells
xlWSh.Range("A8").Select
xlWSh.Activate
xlWSh.Cells.Rows(7).AutoFilter
xlWSh.Cells.Rows(7).EntireColumn.AutoFit
rst.Close
Set rst = Nothing
'Remove prompts to save the report
ApXL.DisplayAlerts = False
xlWBk.SaveAs "N:\EXACT FIT\WESTLAND EXPORT PLUS\Westland_" & Format(Date, "mm.dd.yyyy") & ".xlsx", 51
ApXL.DisplayAlerts = True
'ApXL.Quit
Exit Function
Err_Handler:
DoCmd.SetWarnings True
MsgBox Err.DESCRIPTION, vbExclamation, Err.Number
Exit Function
End Function
SELECT [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].ID, [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].[PART NUMBER], [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].[PART DESCRIPTION], [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].SUPPLIER, [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].COO, [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].[COST W FREIGHT], [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].UOM, [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].QUANITY, [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT].Expr1
FROM [BOM PRICING EXTENDED DETAILS NON BOW S EXPORT]
UNION SELECT [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].ID, [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].[PART NUMBER], [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].[PART DESCRIPTION], [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].SUPPLIER, [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].COO, [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].[COST W FREIGHT], [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].UOM, [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].QUANITY, [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT].Expr1
FROM [BOM PRICING EXTENDED DETAILS PACKAGING S EXPORT];
Option Compare Database
Option Explicit
Private Sub Command579_Click()
Dim dbs As DAO.Database
Dim qryDef As DAO.QueryDef
Dim qryDefFooter As DAO.QueryDef
Dim strSQL As String
Dim strSQLFooter
Dim strWhere As String
Dim lngLen As Long
Set dbs = CurrentDb
strSQL = "SELECT ID, [PART NUMBER], [PART DESCRIPTION], SUPPLIER, COO, [COST W FREIGHT], UOM, QUANITY, Expr1 " & _
"FROM quniExportToExcel"
strSQLFooter = "SELECT ID, [PART NUMBER], QUANITY, Expr4 " & _
"FROM [BOM PRICING EXTENDED DETAILS LABOR S]"
'Number
If Not IsNull(Me.ID) Then
strWhere = strWhere & "([ID] = " & Me.ID & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
strSQL = strSQL
Set qryDef = dbs.CreateQueryDef("qryWestportExport", strSQL)
'DoCmd.OpenQuery qryDef.Name
qryDef.Close
Set qryDef = Nothing
Call SendToExcel("qryWestportExport", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExport"
DoEvents
strSQLFooter = strSQLFooter
Set qryDefFooter = dbs.CreateQueryDef("qryWestportExportFooter", strSQLFooter)
'DoCmd.OpenQuery qryDef.Name
qryDefFooter.Close
Set qryDefFooter = Nothing
Call SendToExcelFooter("qryWestportExportFooter", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExportFooter"
Else
strWhere = Left$(strWhere, lngLen)
strSQL = strSQL & " WHERE " & strWhere
Set qryDef = dbs.CreateQueryDef("qryWestportExport", strSQL)
'DoCmd.OpenQuery qryDef.Name
qryDef.Close
Set qryDef = Nothing
Call SendToExcel("qryWestportExport", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExport"
DoEvents
strSQLFooter = strSQLFooter & " WHERE " & strWhere
Set qryDefFooter = dbs.CreateQueryDef("qryWestportExportFooter", strSQLFooter)
'DoCmd.OpenQuery qryDef.Name
qryDefFooter.Close
Set qryDefFooter = Nothing
Call SendToExcelFooter("qryWestportExportFooter", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExportFooter"
End If
dbs.Close
Set dbs = Nothing
End Sub
Function SendToExcel(strTQName As String, strSheetName As String)
' strTQName is the name of the table or query you want to send to Excel
' strSheetName is the name of the sheet you want to send it to
Dim rst As DAO.Recordset
Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object
Dim fld As DAO.Field
Dim lngMaxRow As Long
Dim lngMaxCol As Long
Dim strPath As String
On Error GoTo Err_Handler
'Location of Template
strPath = "G:\SUE'S STUFF\WORKING DESKTOP\2016 WESTLAND\WESTLAND EXPORT\Book1.xls"
Set rst = CurrentDb.OpenRecordset(strTQName)
Set ApXL = CreateObject("Excel.Application")
Set xlWBk = ApXL.Workbooks.Open(strPath)
ApXL.Visible = True
Set xlWSh = xlWBk.Worksheets(strSheetName)
xlWSh.Range("I1").Value = Me.ID
xlWSh.Range("I2").Value = Me.[COVER PART NUMBER]
xlWSh.Range("I3").Value = Me.[MODELS.DESCRIPTION]
rst.MoveFirst
xlWSh.Range("A8").CopyFromRecordset rst
rst.Close
Set rst = Nothing
'Remove prompts to save the report
ApXL.DisplayAlerts = False
xlWBk.SaveAs "N:\EXACT FIT\WESTLAND EXPORT PLUS\Westland_" & Format(Date, "mm.dd.yyyy") & ".xlsx", 51
ApXL.DisplayAlerts = True
'ApXL.Quit
Exit Function
Err_Handler:
DoCmd.SetWarnings True
MsgBox Err.DESCRIPTION, vbExclamation, Err.Number
Exit Function
End Function
Function SendToExcelFooter(strTQName As String, strSheetName As String)
' strTQName is the name of the table or query you want to send to Excel
' strSheetName is the name of the sheet you want to send it to
Dim rst As DAO.Recordset
Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object
Dim fld As DAO.Field
Dim lngMaxRow As Long
Dim lngMaxCol As Long
Dim strPath As String
On Error GoTo Err_Handler
'Location of Workbook
strPath = "N:\EXACT FIT\WESTLAND EXPORT PLUS\Westland_" & Format(Date, "mm.dd.yyyy") & ".xlsx"
Set rst = CurrentDb.OpenRecordset(strTQName)
Set ApXL = CreateObject("Excel.Application")
Set xlWBk = ApXL.Workbooks.Open(strPath)
Set xlWSh = xlWBk.Worksheets(strSheetName)
rst.MoveFirst
xlWSh.Range("A29").CopyFromRecordset rst
' selects the first cell to unselect all cells
xlWSh.Range("A8").SELECT
xlWSh.Activate
xlWSh.Cells.Rows(7).AutoFilter
xlWSh.Cells.Rows(7).EntireColumn.AutoFit
rst.Close
Set rst = Nothing
'Remove prompts to save the report
ApXL.DisplayAlerts = False
xlWBk.Save
ApXL.DisplayAlerts = True
'ApXL.Quit
Exit Function
Err_Handler:
DoCmd.SetWarnings True
MsgBox Err.DESCRIPTION, vbExclamation, Err.Number
Exit Function
End Function
Option Compare Database
Option Explicit
Private Sub Command579_Click()
Dim dbs As DAO.Database
Dim qryDef As DAO.QueryDef
Dim qryDefFooter As DAO.QueryDef
Dim strSQL As String
Dim strSQLFooter
Dim strWhere As String
Dim lngLen As Long
Set dbs = CurrentDb
strSQL = "SELECT ID, [PART NUMBER], [PART DESCRIPTION], SUPPLIER, COO, [COST W FREIGHT], UOM, QUANITY, Expr1 " & _
"FROM quniExportToExcel"
strSQLFooter = "SELECT ID, [PART NUMBER], QUANITY, Expr4 " & _
"FROM [BOM PRICING EXTENDED DETAILS LABOR S]"
'Number
If Not IsNull(Me.ID) Then
strWhere = strWhere & "([ID] = " & Me.ID & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
strSQL = strSQL
Set qryDef = dbs.CreateQueryDef("qryWestportExport", strSQL)
'DoCmd.OpenQuery qryDef.Name
qryDef.Close
Set qryDef = Nothing
Call SendToExcel("qryWestportExport", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExport"
DoEvents
strSQLFooter = strSQLFooter
Set qryDefFooter = dbs.CreateQueryDef("qryWestportExportFooter", strSQLFooter)
'DoCmd.OpenQuery qryDef.Name
qryDefFooter.Close
Set qryDefFooter = Nothing
Call SendToExcelFooter("qryWestportExportFooter", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExportFooter"
Else
strWhere = Left$(strWhere, lngLen)
strSQL = strSQL & " WHERE " & strWhere
Set qryDef = dbs.CreateQueryDef("qryWestportExport", strSQL)
'DoCmd.OpenQuery qryDef.Name
qryDef.Close
Set qryDef = Nothing
Call SendToExcel("qryWestportExport", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExport"
DoEvents
strSQLFooter = strSQLFooter & " WHERE " & strWhere
Set qryDefFooter = dbs.CreateQueryDef("qryWestportExportFooter", strSQLFooter)
'DoCmd.OpenQuery qryDef.Name
qryDefFooter.Close
Set qryDefFooter = Nothing
Call SendToExcelFooter("qryWestportExportFooter", "Sheet1")
DoCmd.DeleteObject acQuery, "qryWestportExportFooter"
End If
dbs.Close
Set dbs = Nothing
End Sub
Function SendToExcel(strTQName As String, strSheetName As String)
' strTQName is the name of the table or query you want to send to Excel
' strSheetName is the name of the sheet you want to send it to
Dim rst As DAO.Recordset
Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object
Dim fld As DAO.Field
Dim lngMaxRow As Long
Dim lngMaxCol As Long
Dim strPath As String
On Error GoTo Err_Handler
'Location of Template
strPath = "G:\SUE'S STUFF\WORKING DESKTOP\2016 WESTLAND\WESTLAND EXPORT\Book1.xls"
Set rst = CurrentDb.OpenRecordset(strTQName)
Set ApXL = CreateObject("Excel.Application")
Set xlWBk = ApXL.Workbooks.Open(strPath)
'ApXL.Visible = True
Set xlWSh = xlWBk.Worksheets(strSheetName)
xlWSh.Range("I1").Value = Me.ID
xlWSh.Range("I2").Value = Me.[COVER PART NUMBER]
xlWSh.Range("I3").Value = Me.[MODELS.DESCRIPTION]
rst.MoveFirst
xlWSh.Range("A8").CopyFromRecordset rst
rst.Close
Set rst = Nothing
'Remove prompts to save the report
ApXL.DisplayAlerts = False
xlWBk.SaveAs "N:\EXACT FIT\WESTLAND EXPORT PLUS\Westland_" & Format(Date, "mm.dd.yyyy") & ".xlsx", 51
ApXL.DisplayAlerts = True
ApXL.Quit
Exit Function
Err_Handler:
DoCmd.SetWarnings True
MsgBox Err.DESCRIPTION, vbExclamation, Err.Number
Exit Function
End Function
Function SendToExcelFooter(strTQName As String, strSheetName As String)
' strTQName is the name of the table or query you want to send to Excel
' strSheetName is the name of the sheet you want to send it to
Dim rst As DAO.Recordset
Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object
Dim fld As DAO.Field
Dim lngMaxRow As Long
Dim lngMaxCol As Long
Dim strPath As String
On Error GoTo Err_Handler
'Location of Workbook
strPath = "N:\EXACT FIT\WESTLAND EXPORT PLUS\Westland_" & Format(Date, "mm.dd.yyyy") & ".xlsx"
Set rst = CurrentDb.OpenRecordset(strTQName)
Set ApXL = CreateObject("Excel.Application")
Set xlWBk = ApXL.Workbooks.Open(strPath)
Set xlWSh = xlWBk.Worksheets(strSheetName)
ApXL.Visible = True
rst.MoveFirst
xlWSh.Range("A29").CopyFromRecordset rst
' selects the first cell to unselect all cells
xlWSh.Range("A8").SELECT
xlWSh.Activate
xlWSh.Cells.Rows(7).AutoFilter
xlWSh.Cells.Rows(7).EntireColumn.AutoFit
rst.Close
Set rst = Nothing
'Remove prompts to save the report
ApXL.DisplayAlerts = False
xlWBk.Save
ApXL.DisplayAlerts = True
'ApXL.Quit
Exit Function
Err_Handler:
DoCmd.SetWarnings True
MsgBox Err.DESCRIPTION, vbExclamation, Err.Number
Exit Function
End Function