G
Guest
On the first run through this sub the mkDir command makes the c:\Test
directory. The second time I test the sub it stops in debug mode on the
mkDir line.
tia,
Private Sub Form_AfterUpdate()
'*******************************************************************
'Purpose: To update an Excel spreadsheet with each subsequent record
'*******************************************************************
Const STR_DIRECTORY_PATH = "C:\Test\"
Const STR_Filename = "emp.xls"
Dim lngLastError As Long
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Dim EndRow As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
'Check if directory exists if not create it
If Dir(STR_DIRECTORY_PATH) = "" Then
MkDir STR_DIRECTORY_PATH
End If
Set appExcel = Excel.Application
appExcel.Visible = True
Set wbk = appExcel.Workbooks.Open("emp.xls")
Set wks = appExcel.Worksheets("Employees")
wks.Activate
EndRow = Range("A65536").End(xlUp).Select
Range("a1").Offset(0, EndRow + 1).Value = Forms![frmEmployees]!Form![ID]
Range("a2").Offset(0, EndRow + 1).Value =
Forms![frmEmployees]!Form![FirstName]
Range("a3").Offset(0, EndRow + 1).Value = Forms![frmEmployees]!Form![Salary]
Set dbs = Nothing
End Sub
directory. The second time I test the sub it stops in debug mode on the
mkDir line.
tia,
Private Sub Form_AfterUpdate()
'*******************************************************************
'Purpose: To update an Excel spreadsheet with each subsequent record
'*******************************************************************
Const STR_DIRECTORY_PATH = "C:\Test\"
Const STR_Filename = "emp.xls"
Dim lngLastError As Long
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Dim EndRow As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
'Check if directory exists if not create it
If Dir(STR_DIRECTORY_PATH) = "" Then
MkDir STR_DIRECTORY_PATH
End If
Set appExcel = Excel.Application
appExcel.Visible = True
Set wbk = appExcel.Workbooks.Open("emp.xls")
Set wks = appExcel.Worksheets("Employees")
wks.Activate
EndRow = Range("A65536").End(xlUp).Select
Range("a1").Offset(0, EndRow + 1).Value = Forms![frmEmployees]!Form![ID]
Range("a2").Offset(0, EndRow + 1).Value =
Forms![frmEmployees]!Form![FirstName]
Range("a3").Offset(0, EndRow + 1).Value = Forms![frmEmployees]!Form![Salary]
Set dbs = Nothing
End Sub