|
Option Compare Database
Option Explicit
Private Sub cmdCancel_Click()
'close the dialog box
DoCmd.Close
End Sub
Private Sub cmdOk_Click()
'declare an Excel Application object variable named appExcel
Dim appExcel As Excel.Application
Dim sht1 As Worksheet
'declare a Workbook object variable named wkbSales
Dim wkbSales As workbook
'create an Excel Application object and assign its address to the appExcel variable
Set appExcel = CreateObject(Class:="excel.application")
'open a new workbook and assign its address to the wkbSales variable
Set wkbSales = appExcel.Workbooks.Open("C:\Documents and Settings\Stephanie Smith\My
Documents\wkbSales.xls")
Set sht1 = wkbSales.Worksheets("Sheet1")
'enter current record's information in cells A1, A2, and A3 in the first worksheet
sht1.Range("A1") = Application.Forms("salespeople").Controls("txtId")
sht1.Range("A2") = Application.Forms("salespeople").Controls("txtName")
sht1.Range("A3") = Application.Forms("salespeople").Controls("txtSales")
'use the AutoFit method to adjust the size of column A in the first worksheet
sht1.Columns.Range("A1").AutoFit
'make the Excel Application object visible
appExcel.Visible = True
'release the memory allocated to the Excel Application object
Set appExcel = Nothing
'close the form
DoCmd.Close
End Sub
|
|
|
|
|
|
|
|
|
|