I have a command button in Access 2007 which transfers data from a form to an Excel workbook. Once the data is transfered, I would like to run a macro in Excel which emails a copy of the workbook to a specified individual. The transfer from Access to Excel works properly, and the macro in Excel works properly, but I'd like to know if I can have both of these actions take place with the click of one button in Access. Here is the code for the On click event in Access:
Private Sub cmdExportSpecOrd_Click()
Dim strFile As String
Dim oXLS As Object
Dim oWkb As Object
strFile = "J:\Product Management\HP PurchasEdge\Special Orders\Database Templates\Special Order Form Template.xls"
Set oXLS = CreateObject("Excel.Application")
oXLS.Workbooks.Open strFile
Set oWkb = oXLS.Workbooks(1)
oWkb.Worksheets(1).Range("J20") = Me.txtCSRName
oWkb.Worksheets(1).Range("M20") = Me.txtCSRExt
oWkb.Worksheets(1).Range("I16") = Me.txtCustName
oWkb.Worksheets(1).Range("E18") = Me.txtCustName
oWkb.Worksheets(1).Range("K29") = Me.txtCustName
oWkb.Worksheets(1).Range("H18") = Me.txtPhoneNum
oWkb.Worksheets(1).Range("D20") = Me.txtOrdDate
oWkb.Worksheets(1).Range("F20") = Me.txtPO
oWkb.Worksheets(1).Range("L23") = Me.txtCompName
oWkb.Worksheets(1).Range("J25") = Me.txtAddress
oWkb.Worksheets(1).Range("J27") = Me.txtCity
oWkb.Worksheets(1).Range("M27") = Me.cboState
oWkb.Worksheets(1).Range("N27") = Me.txtZip
oWkb.Worksheets(1).Range("J31") = Me.txtCustEmail
oWkb.Worksheets(1).Range("C36") = Me.cboSKU
oWkb.Worksheets(1).Range("F36") = Me.txtProdDesc
oWkb.Worksheets(1).Range("I36") = Me.txtQty
oWkb.Worksheets(1).Range("K36") = Me.txtListPrice
oWkb.Worksheets(1).Range("M36") = Me.txtAzertyCost
oWkb.Worksheets(1).Range("O36") = Me.txtDealerCost
oWkb.Worksheets(1).Range("C37") = Me.cboSKU1
oWkb.Worksheets(1).Range("F37") = Me.txtProdDesc1
oWkb.Worksheets(1).Range("I37") = Me.txtQty1
oWkb.Worksheets(1).Range("K37") = Me.txtListPrice1
oWkb.Worksheets(1).Range("M37") = Me.txtAzertyCost1
oWkb.Worksheets(1).Range("O37") = Me.txtDealerCost1
oWkb.Worksheets(1).Range("C38") = Me.cboSKU2
oWkb.Worksheets(1).Range("F38") = Me.txtProdDesc2
oWkb.Worksheets(1).Range("I38") = Me.txtQty2
oWkb.Worksheets(1).Range("K38") = Me.txtListPrice2
oWkb.Worksheets(1).Range("M38") = Me.txtAzertyCost2
oWkb.Worksheets(1).Range("O38") = Me.txtDealerCost2
oWkb.Worksheets(1).Range("C39") = Me.cboSKU3
oWkb.Worksheets(1).Range("F39") = Me.txtProdDesc3
oWkb.Worksheets(1).Range("I39") = Me.txtQty3
oWkb.Worksheets(1).Range("K39") = Me.txtListPrice3
oWkb.Worksheets(1).Range("M39") = Me.txtAzertyCost3
oWkb.Worksheets(1).Range("O39") = Me.txtDealerCost3
oWkb.Worksheets(1).Range("C40") = Me.cboSKU4
oWkb.Worksheets(1).Range("F40") = Me.txtProdDesc4
oWkb.Worksheets(1).Range("I40") = Me.txtQty4
oWkb.Worksheets(1).Range("K40") = Me.txtListPrice4
oWkb.Worksheets(1).Range("M40") = Me.txtAzertyCost4
oWkb.Worksheets(1).Range("O40") = Me.txtDealerCost4
oXLS.Visible = True
Set oXLS = Nothing
Set oWkb = Nothing
End Sub
The macro name in the Excel workbook is "SpecialOrder" - is there a way to have that run at the end of the code listed above?
Thanks in advance for your help
Private Sub cmdExportSpecOrd_Click()
Dim strFile As String
Dim oXLS As Object
Dim oWkb As Object
strFile = "J:\Product Management\HP PurchasEdge\Special Orders\Database Templates\Special Order Form Template.xls"
Set oXLS = CreateObject("Excel.Application")
oXLS.Workbooks.Open strFile
Set oWkb = oXLS.Workbooks(1)
oWkb.Worksheets(1).Range("J20") = Me.txtCSRName
oWkb.Worksheets(1).Range("M20") = Me.txtCSRExt
oWkb.Worksheets(1).Range("I16") = Me.txtCustName
oWkb.Worksheets(1).Range("E18") = Me.txtCustName
oWkb.Worksheets(1).Range("K29") = Me.txtCustName
oWkb.Worksheets(1).Range("H18") = Me.txtPhoneNum
oWkb.Worksheets(1).Range("D20") = Me.txtOrdDate
oWkb.Worksheets(1).Range("F20") = Me.txtPO
oWkb.Worksheets(1).Range("L23") = Me.txtCompName
oWkb.Worksheets(1).Range("J25") = Me.txtAddress
oWkb.Worksheets(1).Range("J27") = Me.txtCity
oWkb.Worksheets(1).Range("M27") = Me.cboState
oWkb.Worksheets(1).Range("N27") = Me.txtZip
oWkb.Worksheets(1).Range("J31") = Me.txtCustEmail
oWkb.Worksheets(1).Range("C36") = Me.cboSKU
oWkb.Worksheets(1).Range("F36") = Me.txtProdDesc
oWkb.Worksheets(1).Range("I36") = Me.txtQty
oWkb.Worksheets(1).Range("K36") = Me.txtListPrice
oWkb.Worksheets(1).Range("M36") = Me.txtAzertyCost
oWkb.Worksheets(1).Range("O36") = Me.txtDealerCost
oWkb.Worksheets(1).Range("C37") = Me.cboSKU1
oWkb.Worksheets(1).Range("F37") = Me.txtProdDesc1
oWkb.Worksheets(1).Range("I37") = Me.txtQty1
oWkb.Worksheets(1).Range("K37") = Me.txtListPrice1
oWkb.Worksheets(1).Range("M37") = Me.txtAzertyCost1
oWkb.Worksheets(1).Range("O37") = Me.txtDealerCost1
oWkb.Worksheets(1).Range("C38") = Me.cboSKU2
oWkb.Worksheets(1).Range("F38") = Me.txtProdDesc2
oWkb.Worksheets(1).Range("I38") = Me.txtQty2
oWkb.Worksheets(1).Range("K38") = Me.txtListPrice2
oWkb.Worksheets(1).Range("M38") = Me.txtAzertyCost2
oWkb.Worksheets(1).Range("O38") = Me.txtDealerCost2
oWkb.Worksheets(1).Range("C39") = Me.cboSKU3
oWkb.Worksheets(1).Range("F39") = Me.txtProdDesc3
oWkb.Worksheets(1).Range("I39") = Me.txtQty3
oWkb.Worksheets(1).Range("K39") = Me.txtListPrice3
oWkb.Worksheets(1).Range("M39") = Me.txtAzertyCost3
oWkb.Worksheets(1).Range("O39") = Me.txtDealerCost3
oWkb.Worksheets(1).Range("C40") = Me.cboSKU4
oWkb.Worksheets(1).Range("F40") = Me.txtProdDesc4
oWkb.Worksheets(1).Range("I40") = Me.txtQty4
oWkb.Worksheets(1).Range("K40") = Me.txtListPrice4
oWkb.Worksheets(1).Range("M40") = Me.txtAzertyCost4
oWkb.Worksheets(1).Range("O40") = Me.txtDealerCost4
oXLS.Visible = True
Set oXLS = Nothing
Set oWkb = Nothing
End Sub
The macro name in the Excel workbook is "SpecialOrder" - is there a way to have that run at the end of the code listed above?
Thanks in advance for your help