Can anyone help ?
I have this Code running when a form opens to import and update a table from excel - I will be the first to admit I am no expert but the bits run ok when not put in one script - but it keeps opening excel again and again when put together instead of just once. I "borrowed" bits from other Vb examples and cobbled them together.
I want it just to run once then open the message box
here is the code:
Option Compare Database
Option Explicit
Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
Dim objExcel As Object
' Create a new instance of Excel.
Set objExcel = CreateObject("Excel.Application")
' Show the instance of Excel on the screen.
objExcel.Visible = True
' Open a file
objExcel.Workbooks.Open ("C:\DriverControl\Holiday2006-2007.xls")
DoCmd.RunMacro "delay5Seconds"
DoCmd.DeleteObject acTable, "Imported Holidays"
DoCmd.OpenQuery "Imported Holidays Builder"
' close workbook
objExcel.Quit
Set objExcel = Nothing
MsgBox "Holidays Updated"
DoCmd.OpenForm "MainForm"
DoCmd.Close acForm, Me.Name
Exit_Form_Timer:
' Exit Function
Err_Form_Timer:
' Exit Function
End Sub
Thanks
Dean
I have this Code running when a form opens to import and update a table from excel - I will be the first to admit I am no expert but the bits run ok when not put in one script - but it keeps opening excel again and again when put together instead of just once. I "borrowed" bits from other Vb examples and cobbled them together.
I want it just to run once then open the message box
here is the code:
Option Compare Database
Option Explicit
Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
Dim objExcel As Object
' Create a new instance of Excel.
Set objExcel = CreateObject("Excel.Application")
' Show the instance of Excel on the screen.
objExcel.Visible = True
' Open a file
objExcel.Workbooks.Open ("C:\DriverControl\Holiday2006-2007.xls")
DoCmd.RunMacro "delay5Seconds"
DoCmd.DeleteObject acTable, "Imported Holidays"
DoCmd.OpenQuery "Imported Holidays Builder"
' close workbook
objExcel.Quit
Set objExcel = Nothing
MsgBox "Holidays Updated"
DoCmd.OpenForm "MainForm"
DoCmd.Close acForm, Me.Name
Exit_Form_Timer:
' Exit Function
Err_Form_Timer:
' Exit Function
End Sub
Thanks
Dean