Snappy1263
Registered User.
- Local time
- Today, 15:50
- Joined
- Dec 8, 2015
- Messages
- 130
Can I creat another database in 2010 n link the tables n import the queries.
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 = “[COLOR=black][FONT=Segoe UI]G:\SUE'S STUFF\WORKING DESKTOP\2016 WESTLAND\WESTLAND EXPORT\Book1.xls[/FONT][/COLOR][FONT=Segoe UI]"[/FONT]
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 = ????
‘xlWSh.Range("I2").Value = ????
‘xlWSh.Range("I3").Value = ????
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 "[COLOR=black][FONT=Verdana]N:\EXACT FIT\WESTLAND EXPORT PLUS\Westland_[/FONT][/COLOR]" 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
Dim dbs As DAO.Database
Dim qryDef As DAO.QueryDef
Dim strSQL As String
Dim strWhere As String
Dim lngLen As Long
Set dbs = CurrentDb
strSQL = "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]"
'Number
If Not IsNull(Me.txtID) Then
strWhere = strWhere & "([ID] = " & Me.txtID & ") 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
DoEvents
Call SendToExcel("qryWestportExport", "Sheet1")
DoEvents
DoCmd.DeleteObject acQuery, "qryWestportExport"
Else
strWhere = Left$(strWhere, lngLen)
strSQL = strSQL & " WHERE " & strWhere
Set qryDef = dbs.CreateQueryDef("qryWestportExport", strSQL)
'DoCmd.OpenQuery qryDef.Name
qryDef.Close
Set qryDef = Nothing
DoEvents
Call SendToExcel("qryWestportExport", "Sheet1")
DoEvents
DoCmd.DeleteObject acQuery, "qryWestportExport"
End If
dbs.Close
Set dbs = Nothing
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 = “[COLOR=black][FONT=Segoe UI]G:\SUE'S STUFF\WORKING DESKTOP\2016 WESTLAND\WESTLAND EXPORT\Book1.xls[/FONT][/COLOR][FONT=Segoe UI]"[/FONT]
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.[[COLOR=black][FONT=Verdana]COVER PART NUMBER][/FONT][/COLOR]
‘xlWSh.Range("I3").Value = Me.[[COLOR=black][FONT=Verdana]DESCRIPTION][/FONT][/COLOR]
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 "[COLOR=black][FONT=Verdana]N:\EXACT FIT\WESTLAND EXPORT PLUS\Westland_[/FONT][/COLOR]" 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
Dim dbs As DAO.Database
Dim qryDef As DAO.QueryDef
Dim strSQL As String
Dim strWhere As String
Dim lngLen As Long
Set dbs = CurrentDb
strSQL = "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]"
'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
DoEvents
Call SendToExcel("qryWestportExport", "Sheet1")
DoEvents
DoCmd.DeleteObject acQuery, “qryWestportExport"
Else
strWhere = Left$(strWhere, lngLen)
strSQL = strSQL & " WHERE " & strWhere
Set qryDef = dbs.CreateQueryDef("qryWestportExport", strSQL)
'DoCmd.OpenQuery qryDef.Name
qryDef.Close
Set qryDef = Nothing
DoEvents
Call SendToExcel("qryWestportExport", "Sheet1")
DoEvents
DoCmd.DeleteObject acQuery, "qryWestportExport"
End If
dbs.Close
Set dbs = Nothing